nodelist
Each node has a ChildNodes property that holds the NodeList object. NodeList is a class array object that holds an ordered set of nodes that can be accessed by location. The uniqueness of the NodeList object is that it is actually the result of dynamically executing the query based on the DOM structure, so changes in the DOM structure can be automatically reflected in the nodelist. NodeList is "dynamic":
var arrayofnodes = Array.prototype.slice.call (somenode.childnodes, 0);//Can be used to convert nodelist to a true array
NamedNodeMap
Similar to NodeList, it is also a collection of "dynamic". The attributes of an element are represented by a attr node, each of which is saved in the NamedNodeMap object. The NamedNodeMap object has the following methods.
name |
function |
getNamedItem (name) |
Returns the node with the NodeName property equal to name |
RemoveNamedItem (name) |
Remove the node with the NodeName property equal to name from the list |
SetNamedItem (node) |
To add a node to the list, indexed by the NodeName property of the node |
Item (POS) |
Returns the node at the location of the digital POS |
Example
var id = element.attributes.getNamedItem (' id '). nodevalue;
or
var id = element.attributes["id"].nodevalue;
htmlcollection
A method commonly used to obtain an element reference is getElementsByTagName (). That is, to get the label name of the element, and return the nodelist containing 0 or more elements. In an HTML document, this method returns a Htmlcollection object as a "dynamic" collection that is very similar to nodelist.
Example: Gets all the elements in the page and returns a htmlcollection.
var image = document.getElementsByTagName ("img");
Some methods
name |
function |
Item () or square brackets |
Accessing items in a Htmlcollection object |
Nameditem () |
Use this method to get the items in the collection through the element's name attribute |
//e.g. just image
var myimage = Image.nameditem ("MyImage");
Returns the label of the first row