Node: Node labels, text, and comments in a page. . . They are all nodes
childNodes: Get all child nodes
children: Get all element child nodes
parentNode: Get the parent node
##previousSibling: Get the previous brother node
##nextSibling: Get the next brother nodefirstChild: Get the first of all child nodes
lastChild: Get the last of all child nodes
The node types we need to master in js:
## Capital The tag name is null
## Text node (text) 3
#document 9 #document null
Note:In standard browsers, we treat space and Enter as our Text node
Method: Simulate our children method to obtain the element child node under the specified element
##
/ * getMyChildren:获取制定元素下的所有的元素节点 * @parameter:
* ele:我们要获取谁下面的,就把谁传过来
tagName:获取元素的类型 * @return: * 我们最后获取的元素子节点 * by xxxxxxxxx * */function getMyChildren(ele,tagName){var ary = [],nodes = ele.childNodes;for(var i = 0;i){var cur = nodes[i];if(cur.nodeType===1){
if(tagName){
if(cur.nodeName.toLowerCase===tagName.toLowerCase){
ary.push(cur)
}
}else{
ary.push(cur);
} } }return ary; }
Get the previous brother element child node of an element
pre =(pre && pre.nodeType!==1=
function prevAll(ele){var pre = ele.previousSibling,ary = [];while(pre){if(pre,nodeType===1){ ary.unshift(pre); } pre = pre.previousSibling; }return ary; }
The above is the detailed content of Summary of node and relationship properties in DOM. For more information, please follow other related articles on the PHP Chinese website!