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

SQL: Use PowerShell to Generate a Database Object From Another Object

Have you ever wondered about the prospect of automating T-SQL executions on Windows? As your…

“Simon” Piano Game JavaScript Code

Demo: https://blog.kimconnect.com/wp-content/projects/pianogame.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>…

PowerShell: Get IP’s From Computer Names

Resolve from Names to IPs: $names=@( 'TESTVM001', 'TESTVM002', 'TESTVM003' ) foreach($name in $names){ $ips =…