Tutorial by Examples

Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value). var a = document.querySelector("a"), url = a.href; Other attributes, including data-attributes can be accessed as follows: var a = document.querySelector("a"), ...
Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value). document.querySelector("a").href = "#top"; Other attributes, including data-attributes can be set as follows: document.querySelector("a").setAttribute("...
To remove an attribute, including directly accessible properties document.querySelector("a").removeAttribute("title"); Data attributes can also be removed as follows (modern browsers): // remove "data-foo" attribute delete document.querySelector("a").dat...

Page 1 of 1