# Element Attributes

When working with an Element you will often want to read the value from or update an attribute within that Element.

# Element properties concerning Attributes

element.attributes; //returns a list of the attributes in the element
1

# Element methods concerning Attributes

element.getAttribute(attrName); //get the value of an attribute
element.setAttribute(attrName, attrValue); //set a new value
element.hasAttributes(); //check if an element has any attributes
element.hasAttribute(attrName); //check for a specific attribute
element.removeAttribute(attrName); //delete an attribute from an element
1
2
3
4
5

# MDN reference

get attribute

set attribute

remove attribute

dataset properties

Back to Week 6 main page

Last Updated: 6/13/2020, 11:30:19 PM