O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding DOM Objects by ID

var containerObj = document.getElementById("myDiv");

The simplest method to find an HTML element is to use the value of the id attribute with the document.getElementById(id) function. The document.getElementById(id) function searches the DOM for an object with a matching id attribute. If that object is found, the function returns the DOM object.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required