Posted On April 6, 2019

Where to Put JavaScript Codes?

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Where to Put JavaScript Codes?

Most often, JavaScript is placed between the <head> and </head> section. However, that may not be practical for in some situations such as this single blog post. Fortunately, JavaScript may also be placed anywhere between the <body> and </body> tags. In fact, it’s known that placing .js codes closer to the bottom of the <body> section, right before the </body> tag, does speed up page loads. Here is a demo of this practice:

HTML Code:


<!DOCTYPE html>
<html>
<body>
<h2>JavaScript in Body</h2>
<p id="test">Click da button.</p>

<button type="button" onclick="myFunction()">Da Button</button>

<script>
function myFunction() {
document.getElementById("test").innerHTML = "Da Button has been pressed.";
}
</script>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

JavaScript: Build a Tic Tac Toe Game (without AI)

Demo: https://blog.kimconnect.com/wp-content/projects/ticTacToeGame.html CSS Code: @import url('https://fonts.googleapis.com/css?family=Merienda');body{ font-family: 'Merienda', cursive; font-weight: bold;}#gameBoard { width: 396px; //…

PowerShell: Activate Remote Windows

$remoteWindows="SHERVER01","SHERVER02"$licenseKey="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"function activateWindows{ param( [string]$key ) $licensingService = get-wmiObject -query "select * from SoftwareLicensingService" -computername $env:computername;…

PowerShell: Get CRC Signature of a File

2/10/20 Update: xxHash will beat both of these in term of speed. Hence, this blog…