← CodePrimer
JavaScript Beginner Dom

document.getElementById

How do I select one element by id?

Classic unique selector.

Sample
const submitButton = document.getElementById('btnSubmit');
submitButton?.addEventListener('click', () => {
  console.log('clicked');
});

Notes

IDs must be unique on the page.

Keywords: getElementById · dom · select · id

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share