- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript DOM Attributes
JavaScript DOM
JavaScript DOM Attributes
JavaScript reads and changes HTML attributes with
getAttribute,setAttributeanddataset.
Attributes are the extra information written inside a tag, like src or href.
Many of them can also be reached as a plain property.
Example
Example
javascript
document.body.innerHTML = '<a id="link" href="/about">About</a>';
const link = document.getElementById("link");
console.log(link.getAttribute("href"));The output is /about.
