Modifying Element Attributes
Explore how to use JavaScript methods like getAttributeNames, getAttribute, setAttribute, and removeAttribute to modify HTML element attributes. This lesson helps you enhance web page interactivity by dynamically changing element properties within the DOM.
Element.getAttributeNames()
Use the Element.getAttributeNames() function to get an array containing the names of the HTML element’s attributes.
Element.getAttribute(name)
You can access the value of a specific attribute within an HTML element using Element.getAttribute() passing the attribute’s name as a string argument.
Element.setAttribute(name, value) + Element.removeAttribute(name)
You can change the value of an attribute using the setAttribute() function. Additionally, you can remove attributes using the removeAttribute() function.
Exercise
Modify the following ordered list programmatically to use big Roman numerals for the list items.