DEV Community

Ian Jones
Ian Jones

Posted on • Updated on

Select a DOM element with getElementByID

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

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>
    <meta charset="utf-8" />
    <title>Select an Element with document.getElementById</title>
      <li id="movie-1">Peanut Butter Falcon</li>
      <li id="movie-2">Knives Out</li>

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

That's it!

Top comments (1)

rspsuresh profile image
suresh rampaul

Very simple one