Where is write the javascript code in html page

Hi, 

in this article we talk about "Where is write the javascript code in html page". This is important topic for you because javascript code will be different location in the html page.

Javascript code must be inserted between <script> and <script> tags.

for Example 

<script>
document.getElementById("txtName").innerHTML = "my name is Cengiz Atilla";
</script>

We can write the javascript code in head tag or body tag. Just we have to  be careful the javascript code will be in script tags.

We can write the Javascript code in html or external js file. If we write an external js file, we need to refer to the external js file on the html page when we want to use it.

for example 

testJavascriptCode.js 

function myFunction() {
   document.getElementById("txtName").innerHTML = "My name is Cengiz ATİLLA";
}

test.html

<script src="testJavascriptCode.js"></script>
<head>
<title> Where is write the javascript code in html page </title>
</head>
<body>
Hello World
</body>

in this article we learned where can we write javascript code in html page.it is important because we usually write javascript code in html page.

 

Add comment