Javascript DOM provides a getElementsByTagName method that can be accessed using the documentElement property of document object. getElementsByTagName method returns the node list array of HTML document elements present in the HTML web page. You can pass the name of the particular HTML tag such as div, span, p etc whose list of array you want to collect. documentElement property of document object returns the root HTML element of the HTML document. Later on, in Javascript tutorials we will discuss about the getElementsByTagName method to access the nodes of XML documents also.
var nodeList = document. documentElement. getElementsByTagName ( "TAG NAME" );
Above syntax can be used to get the list of all the similar HTML elements e.g.: HTML <div> tag, HTML <span> tag.
E.g.:
var nodeList = document. documentElement. getElementsByTagName ( "div" );
Above example code for getElementsByTagName will return the collection of all the div elements in the HTML document.
You can access the following functions and properties of getElementsByTagName method:
You can pass * at the place of HTML tag name to get the collection of all the available HTML elements present in the HTML document.
Be the first to rate this post
Tags: javascript, html, dom, javascript document getelementsbytagname, html div tag, html span tag, html p tag, javascript getelementsbytagname, javascript documentelement, javascript document object, getelementsbyname item, getelementsbyname length, getelementsbyname nameditem, dhtml
10/14/2008 1:05:52 PM