Home / Programs / How to Place JavaScript Code in Body section
Programming Example

How to Place JavaScript Code in Body section

👁 301 Views
💻 Practical Program
📘 Step by Step Learning
How to Place JavaScript Code in Body section

Program Code

<!DOCTYPE html>
<html>
<body>

<h2>Place Your JavaScript Code in Body</h2>

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

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

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph modified.";
}
</script>

</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.