Home / Programs / How JavaScript can change the style of an HTML element
Programming Example

How JavaScript can change the style of an HTML element

👁 398 Views
💻 Practical Program
📘 Step by Step Learning
JavaScript can change the style of an HTML element

Program Code

<!DOCTYPE html>
<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p id="demo">JavaScript can change the style of an HTML element.</p>

<button type="button" onclick="document.getElementById('demo').style.fontSize='40px'">Click Me!</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.