Home / Programs / How to Place JavaScript code in Head
Programming Example

How to Place JavaScript code in Head

👁 292 Views
💻 Practical Program
📘 Step by Step Learning
How to Place JavaScript code in Head

Program Code

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</head>
<body>

<h2>Place your JavaScript code in Head</h2>

<p id="demo">This is a Paragraph.</p>

<button type="button" onclick="myFunction()">Check it</button>

</body>
</html> 

Output

Run above code

Explanation

No

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.