Skip to main content Accessibility Feedback

Attributes & Properties

Element.setAttribute()

Set an attribute (including data attributes) on an element.

let elem = document.querySelector('#lunch');
elem.setAttribute('data-sandwich', 'turkey');