How to change the style of HTML elements in JavaScript HTML DOM
Editor to share with you how to change the style of HTML elements in JavaScript HTML DOM. I hope you will get something after reading this article. Let's discuss it together.
JavaScript HTML DOM-change CSS
HTML DOM allows JavaScript to change the style of HTML elements.
Change the HTML style
To change the style of the HTML element, use this syntax:
Document.getElementById (id). Style.property=new style
The following example will change
Style of the element:
Hello World!
Hello World!
Document.getElementById ("p2") .style.color = "blue"; document.getElementById ("p2") .style.fontFamily = "Arial"; document.getElementById ("p2") .style.fontSize = "larger"
The above paragraph has been modified by a script.
The following example changes the style of the HTML element of id= "id1" when the user clicks the button:
My Heading 1