Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change the style of HTML elements in JavaScript HTML DOM

Shulou Source: shulou.com Published: 2022-06-01 13:13:18 09月23日 Update

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

Tags: Elements styles facets articles examples done examples buttons text more paragraphs users knowledge scripts industry grammar information information channels this is the channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Microsoft Linux macOS