Java Reference
In-Depth Information
figure 9-5  
Methods of the Element Object: Getting and Setting Attributes
If you want to set any element attributes, other than the style attribute, you should use the
DOM‐specific methods of the Element object.
The three methods you can use to return and alter the contents of an HTML element's
attributes are getAttribute() , setAttribute() , and removeAttribute() , as shown in the
following table.
methods of the element objeCt
desCription
Returns the value of the supplied attribute
Returns null or an empty string if the attribute does
not exist
getAttribute(attributeName)
setAttribute(attributeName,
value)
Sets the value of an attribute
Removes the value of an attribute and replaces it
with the default value
removeAttribute(attributeName)
Let's take a quick look at how these methods work now.
Search WWH ::




Custom Search