Functions to reach an element in the page

getElementById('elementID')
returns the element with the id elementID as an object.
getElementsByTagName('tag')
returns all elements with the name tag as an array.

Of course you can mix and match these two. Some examples:

Example:

document.getElementById('navigation').getElementsByTagName('a')[3];
returns the fourth link inside the element with the ID 'navigation'
document.getElementsByTagName('div')[2].getElementsByTagName('p')[0];
returns the first paragraph inside the third div in the document.

0 comments: