Demonstration Tools: Firefox – Firebug tool
<html> <body> <img src="image.jpeg" class="image" id="demoImage" alt="Demo Image"/> </body> </html>
getAttribute(); setAttribute(,); hasAttribute(); removeAttribute();
getAttribute is as the name suggest a method that returns the value of an attribute. As you can see in the example below, when we invoke the method on the element Node this return the value of the attribute we pass as an argument.
This method allows us to make changes to an existing attribute or add a new attribute to the element. This takes two arguments, which are a pair of key and value for the attribute and its value.
<img src="image.jpeg" class="image" id="demoImage" alt="Demo Image" title="Image Title"/>
This method takes in the name of attribute and return true if the attribute exists and false if it does not.
Takes the name of an attribute and remove that attribute if that exists in the element DOM.
<img class="image" id="demoImage" src="image.jpeg" title="Image" />