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.