Home Web Front-end JS Tutorial Sibling nodes in DOM script programming_javascript skills

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 Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the ways to obtain DOM nodes in Vue3 What are the ways to obtain DOM nodes in Vue3 May 11, 2023 pm 04:55 PM

What are the ways to obtain DOM nodes in Vue3

DOM manipulation guide in PHP DOM manipulation guide in PHP May 21, 2023 pm 04:01 PM

DOM manipulation guide in PHP

What does vue dom mean? What does vue dom mean? Dec 20, 2022 pm 08:41 PM

What does vue dom mean?

Sharing tips on using jQuery sibling nodes Sharing tips on using jQuery sibling nodes Feb 27, 2024 pm 12:45 PM

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 What is the reason why ref binding to dom or component fails in vue3 and how to solve it May 12, 2023 pm 01:28 PM

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 How to automate tasks using shell scripts Jun 18, 2023 pm 01:34 PM

How to automate tasks using shell scripts

What are the dom and bom objects? What are the dom and bom objects? Nov 13, 2023 am 10:52 AM

What are the dom and bom objects?

What is the difference between bom and dom What is the difference between bom and dom Nov 13, 2023 pm 03:23 PM

What is the difference between bom and dom

See all articles