Tutorial by Examples

document.getElementById('uniqueID') will retrieve <div id="uniqueID"></div> As long as an element with the given ID exists, document.getElementById will return only that element. Otherwise, it will return null. Note: IDs must be unique. Multiple elements cannot have the...
document.getElementsByClassName('class-name') will retrieve <a class="class-name">Any</a> <b class="class-name">tag</b> <div class="class-name an-extra-class">with that class.</div> If no existing elements contain the given c...
document.getElementsByTagName('b') will retrieve <b>All</b> <b>of</b> <b>the b elements.</b> If no elements with the given tag name exist, an empty collection will be returned.
Consider following html code <ul> <li id=“one” class=“main”>Item 1</li> <li id=“two” class=“main”>Item 2</li> <li id=“three” class=“main”>Item 3</li> <li id=“four”>Item 4</li> </ul> Following dom tree will be constructed ba...
In modern browsers [1], it is possible to use CSS-like selector to query for elements in a document -- the same way as sizzle.js (used by jQuery). querySelector Returns the first Element in the document that matches the query. If there is no match, returns null. // gets the element whose id=&quot...

Page 1 of 1