Thursday, February 19, 2015

DOM Element Nodes

By tagging an element node with an id, we can search directly to the specific node in the DOM tree via JavaScript functions:

document.getElementById("header") will position the access to


To access a particular type of element, use documnet.getElementByByTagName.  For example, to access the first paragraph in the document,

document.getElementByTagName("p")

The function returns a Nodelist.  To find out how many elements in the Nodelist:

document.getElementByTagName("p").length

Jump access over the list elements:

document.getElementByTagName.item(0) or document.getElementByTagName[0] for the first element item in the list.

Element can also be access via the CSS class name using getElementByClassName()

For example


No comments: