Sibling nodes in DOM script programming_javascript skills
May 16, 2016 pm 06:42 PM
dom
Sibling node
Script programming
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.
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the ways to obtain DOM nodes in Vue3

Sharing tips on using jQuery sibling nodes

What is the reason why ref binding to dom or component fails in vue3 and how to solve it

How to automate tasks using shell scripts

What is the difference between bom and dom
