Friday, February 20, 2015

DOM Attribute Node

Attributes exists in HTML tag.  For example, class attribute in below tag

/local/small.jpg/' id=

JavaScript has the following call to manipulate the attribute in a specific tag.

hasAttribute() tests if the attribute exists in the tag
getAttribute() retrieve the value of the attribute such as "show" above
setAttribute() set a value to the attribute
removeAttribute() remove the attribute from the tag

For example,

document.getElementById("pic").getAttribute("class")

No comments: