Sibling node _ javascript skills in DOM Script Programming

Source: Internet
Author: User
Tags mootools
You can use the previussibling and nextSibling attributes between sibling nodes to access different subnodes at the same level. What if this sibling node is an element or a text node running on a modern browser? Except IE, the browser uses a line break as the text node of the content (nodeType is 3 ). If it is an element, nodeType is 1. The following is a practical method to find them:

The Code is as follows:


LastSibling: function (node ){
Var tempObj = node. parentNode. lastChild;
While (tempObj. nodeType! = 1 & tempObj. previussibling! = Null)
{
TempObj = tempObj. previussibling;
}
Return (tempObj. nodeType = 1 )? TempObj: false;
}


This is the source code of the lastSibling method in the DOMhelp library in JavaScript. Similar to the source code in the mootools Library:

The Code is as follows:


'Last-child ': function (){
Var element = this;
While (element = element. nextSibling )){
If (element. nodeType = 1) return false;
}
Return true;
}


This is the last-child () method in the source code of Mootools 1.2.4.

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.