Post Top Ad

Tuesday, November 21, 2017

HTML DOM setAttribute() Method

The setAttribute() method adds the specified attribute to an element and gives it the specified value.




If the specified attribute already exists, only the value is set/changed.

Note: Although it is possible to add the style attribute with a value to an element with this method, it is recommended that you use properties of the Style object instead for inline styling because this will not overwrite other CSS properties that may be specified in the style attribute:

Here an example: 

No comments:

Post a Comment