Attribute Bench
Read and change HTML attributes with getAttribute and setAttribute.
Live elements
Attribute values appear here.
Change attributes
Important HTML
Use attributes for href, target, title, and disabled. Prefer classList and dataset for classes and data-*.
<a id="court-link" href="https://example.com" target="_self">Visit the court site</a>
<div id="badge" class="jersey-badge" title="Home jersey">12</div>
<button id="tipoff" type="button">Tip off</button>
Important JavaScript
Read or write any HTML attribute by name. Remove disabled to enable the button again.
courtLink.getAttribute("href");
courtLink.setAttribute("href", hrefInput.value);
courtLink.setAttribute("target", targetInput.value);
tipoff.setAttribute("disabled", "disabled");
tipoff.removeAttribute("disabled");