Skip to main content Accessibility Feedback

Attributes & Properties


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

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

Join the Lean Web Club! Coaching. Courses. Coding resources. Get the skills, confidence, and support you need to learn front-end web development and achieve long-term success.

Find this useful? You can support my work by purchasing an annual membership.