noted from 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.
childNodes- returns an array of all the nodes inside the current one. There is also
firstChildandlastChild, which are shorter versions
forchildNodes[0]andchildNodes[this.childNodes.length-1]. parentNode- The element containing this one
nextSibling- the next element on the same level in the document tree
previousSibling- the previous element on the same level in the document tree
Attributes
attributes- returns an array of all the attributes of this element. Does not
work with Internet Explorer below version 6.
data- returns or sets the textual data of the node
nodeName- returns the name of the node (the HTML element name)
nodeType- returns the type of the node — 1 is an element node, 2 attribute and 3 text.
nodeValue- returns or sets the value of the node. This value is the text when
the node is a textnode, the attribute if it is an attribute or null if it
is an element. getAttribute(attribute)- returns the value of the attribute
attribute. - Length
- returns the length of array
- e.g.
imgs=document.getElementsByTagName('img'); for(i=0;i<imgs.length;i++)
Example
function findimg(){ var image; image=document.getElementById('home'); if (image) { image.style.border='3px dashed #ccc'; }}
Find file type
ftype = IMGID.src.substring(src.lastIndexOf('.'), src.length);