DEV Community

Ian Jones
Ian Jones

Posted on • Edited on

3

Select a DOM element with getElementByID

If you would prefer to watch this post, you can do so with this community resource lesson on egghead.io.

Getting an element by id is so common that the document object has a helper function for us to use.

Given this html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Select an Element with document.getElementById</title>
  </head>
  <body>
    <ul>
      <li id="movie-1">Peanut Butter Falcon</li>
      <li id="movie-2">Knives Out</li>
    </ul>
  </body>
</html>

We can grab our <li id="movie-2">Knives Out</li> by calling document.getElementById('movie-2').

That's it!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
rspsuresh profile image
suresh rampaul

Very simple one

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay