Skip to main content Accessibility Feedback

Attributes & Properties

Element.getAttribute()

Get attributes (including data attributes) on an element.

let elem = document.querySelector('#lunch');
let sandwich = elem.getAttribute('data-sandwich');