DOM Attributes Flashcards
attribute.name
var x = document.getElementsByTagName(“BUTTON”)[0].attributes[0].name;
Returns the name of an attribute
attribute.value = value
var x = document.getElementsByTagName("IMG")[0]; x.getAttributeNode("src").value = "pic_bulbon.gif";
Sets or returns the value of the attribute
attribute.specified
var x = document.getElementById(“demo”).attributes[0].specified;
Returns true if the attribute has been specified, otherwise it returns false
namednodemap.getNamedItem(nodename)
var btn = document.getElementsByTagName("BUTTON")[0]; btn.attributes.getNamedItem("onclick").value;
Returns a specified attribute node from a NamedNodeMap
namednodemap.item(index)
var x = document.getElementsByTagName(“BUTTON”)[0].attributes.item(0).nodeName;
Returns the attribute node at a specified index in a NamedNodeMap
namednodemap.length
Returns the number of attribute nodes in a NamedNodeMap
namednodemap.removeNamedItem(nodename)
var btn = document.getElementsByTagName("INPUT")[0]; btn.attributes.removeNamedItem("type");
Removes a specified attribute node
namednodemap.setNamedItem(node)
var h = document.getElementsByTagName("H1")[0]; var typ = document.createAttribute("class"); typ.value = "democlass"; h.attributes.setNamedItem(typ);;
Sets the specified attribute node (by name)