Documentation

Student-friendly HTML, CSS, and JavaScript reference with examples

Sections

getAttribute

Gets the value of an HTML attribute.

const button = document.querySelector('button');
const tabId = button.getAttribute('data-tab');
const href = link.getAttribute('href');

Commonly used with data attributes to store custom information on elements.