ArticleDirectory
Internet Explorer has been used for a long time, and many new APIs are unavailable. For example, in dom1.0, we all know the nextsibling, previussibling, childnodes, firstchild, lastchild, parentnode, and children attributes. However, the traversal API was standardized a year ago, it is classified into a series with nextelementsibling, previuselementsibling, firstelementchild, and lastelementchild. However, standard browsers also support more powerful traversal and provide filtering functions.
Nodeiterator
This is an object. to use it, you need to call the document. createnodeiterator method.
VaR nodeiterator = Document. createnodeiterator (root, whattoshow, filter, entityreferenceexpansion );
The first parameter: Which node to traverse, including itself.
The second parameter is a number used to determine the type of nodes to traverse.
Nodefilter. show_all =-1nodefilter. show_element = 1nodefilter. show_attribute = 2nodefilter. show_text = 4nodefilter. show_cdata_section = 8nodefilter. show_entity_reference = 16nodefilter. show_entity = 32nodefilter. show_processing_instruction = 64nodefilter. show_comment = 128nodefilter. show_document = 256nodefilter. show_document_type = 512nodefilter. show_document_fragment = 1024nodefilter. show_notation = 2048
Third parameter: an object in a very fixed format, or simply null.
{Acceptnode: function (node) {return nodefilter. filter_accept ;},// nodefilter. filter_accept can be changed to nodefilter. filter_reject or nodefilter. filter_skip.
The fourth parameter is a Boolean value. If it is set to false, it is correct.
An example is to obtain all element nodes of the body, including the body itself.
VaR nodeiterator = Document. createnodeiterator (document. Body, nodefilter. show_element, {acceptnode: function (node) {return nodefilter. filter_accept; }}, false );
For more information, click here
Treewalker
The usage is basically the same as that of nodeiterator.
VaR treewalker = Document. createtreewalker (root, whattoshow, filter, entityreferenceexpansion );
In one example, all element nodes of the body are obtained, but the body itself is not included.
VaR treewalker = document. createtreewalker (document. body, nodefilter. show_element, {acceptnode: function (node) {return nodefilter. filter_accept ;}}, false); var nodelist = new array (); While (treewalker. nextnode () nodelist. push (treewalker. currentnode); alert (nodelist)
For more information, click here or
Here
// Get all element, comment, and text nodes in the document
Document. getnodes (node. element_node, node. comment_node, node. text_node );