Home > Web Front-end > JS Tutorial > body text

Sibling nodes in DOM script programming_javascript skills

WBOY
Release: 2016-05-16 18:42:53
Original
1334 people have browsed it

Browsers other than IE use line breaks as text nodes (nodeType is 3). For elements, nodeType is 1. Here's a practical way to find them:

Copy the code The code is as follows:

lastSibling:function( node){
var tempObj = node.parentNode.lastChild;
while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)
{
tempObj=tempObj.previousSibling;
}
return (tempObj.nodeType==1)?tempObj:false;
}

This is the source code of the lastSibling method in the DOMhelp library in the book "JavaScript in a Simple Language". It is similar to the source code implemented in the mootools library:
Copy the code 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 Mootools 1.2.4 source code.
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template