"> Summary of node and relationship properties in DOM-JS Tutorial-php.cn

Summary of node and relationship properties in DOM

PHP中文网
Release: 2017-06-21 13:20:59
Original
1077 people have browsed it
    Title 

培训课程

  • html+css
  • javascript
  • 正式课
  • 移动端课程
  • node.js正式课
Copy after login

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 node

firstChild: 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{
Copy after login
            ary.push(cur);
Copy after login
            } } }return ary; }
Copy after login

Get the previous brother element child node of an element

pre =(pre && pre.nodeType!==1=
Copy after login
Get all the brother element nodes of an element

function prevAll(ele){var pre = ele.previousSibling,ary = [];while(pre){if(pre,nodeType===1){ ary.unshift(pre); } pre = pre.previousSibling; }return ary; }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!