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

Resolving LDAPS Connection Errors

Errors: Can not connect to remote server: 5059 ERROR_CERTIFICATE_ERROR (unable to read server certificates from…

PowerShell: How to Reset Windows Update Service

# resetWindowsUpdateService # This is a legacy method of reseting Windows Update # Since most…

How To Invoke Functions as Background Jobs

Invoke-Command, Start-Job, Multi-Tasking is what good coders should aspire toward. Here, we're looking at some…