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

Methods to Embed JavaScript Codes into WordPress

Insert Headers and Footers Plugin - automatically apply script site wide Shortcoder Plugin - make…

Quick Snippet to Copy NTFS Permissions Between SMB Shares

The experimental script below will sync permissions of a folder toward another.WARNING: if sub-folders at…

PowerShell: Detect Antivirus Name on a Windows Machine

function getAntivirusName { $wmiQuery = "SELECT * FROM AntiVirusProduct" $antivirus = Get-WmiObject -Namespace "root\SecurityCenter2" -Query…