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

Manual Sync for Office 365 Azure-AD Integration

1. Perform Prerequisites:* a. Install Dot Net Framework 4.5 )* b. Install Windows Management Framework…

Methods to Embed JavaScript Codes into WordPress

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

PowerShell: Installing or Including an Application On a Computer or Scripting Session

Sample Usage: PS C:\WINDOWS\system32> includeapp -appName notepadplusplus -appExe notepad++notepadplusplus version 7.91.0.0 already exists.True function includeApp($appName,$appExe=$False,$version){…