getElementById('elementID')
- returns the element with the id
elementID
as anobject
. getElementsByTagName('tag')
- returns all elements with the name
tag
as anarray
.
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:
Post a Comment