Dom pointer Function

Source: Internet
Author: User

1. Return the first child element or null of the specified element.

Function first (OBJ) {var E = obj. firstchild; // obtain the first child node of the element while (E & E. nodetype! = 1) {// if the child node exists and the type is not equal to the element, search for the next node until the node type is E = E. nextsibling;} return E ;}

2. Return the last child element or null of the specified element.

Function last (OBJ) {var E = obj. lastchild; // obtain the last child node of the element while (E & E. nodetype! = 1) {// if the child node exists and the type is not equal to the element, search for the previous node until the node type is E = E. previussibling;} return E ;}

3. parentnode: Obtain the parent element of a specified node.

// Extend the parentnode pointer function to manipulate multiple parent elements at a time. // parameter: OBJ indicates the current node, and N indicates the level of the parent element to be manipulated. // return value: returns the function parent (OBJ, n) {var n = n | 1; // if the second parameter value is not specified, returns the parent element for (VAR I = 0; I <n; I ++) {// layer-by-layer traversal of the parent element if (E. nodetype = 9) break; // return the root element if (E! = NULL) E = E. parentnode; // obtain the parent element of the upper level }}

3. Obtain the last adjacent element or null of the specified element.

function pre(obj){  var e = obj.previousSibling;  while(e && e.nodetype != 1){    e = e.previousSibling;  }  return e;}

4. Obtain the next adjacent element or null of the specified element.

function next(obj){  var e = obj.nextSibling;  while(e && e.nodeType != 1){    e = e.nextSibling;  }  return e;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.