Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nextsibling vs nextelementsibling

// nextElementSibling always returns an element. 
// nextSibling can return any kind of node.
// They are the same for your example, but different in other
<p>
  <span id="span-01">Here is span-01</span>
  Some text at the top level
  <span id="span-02">Here is span-02</span>
</p>
document.getElementById('span-01').nextElementSibling //is  span-02
document.getElementById('span-01').nextSibling // is the text node containing 
											  //  "Some text at the top level" 
//note:
//
<div id="div-1">Here is div-1</div> 
<div id="div-2">Here is div-2</div>
var el = document.getElementById('div-1').nextSibling // is #text node
var el2 = document.getElementById('div-2').nextSibling // is #text node
//text nodes are inserted in the DOM where whitespace occurs between tags
//(i.e. after the closing tag of an element and before the opening tag of the next).
//source : https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSibling#example
Comment

PREVIOUS NEXT
Code Example
Javascript :: console.time 
Javascript :: javascript class constructor 
Javascript :: expressjs path optional parameters 
Javascript :: js write and get cookie 
Javascript :: unload in jquery 
Javascript :: javascript select first n elements from array 
Javascript :: insert item into array specific index javascript 
Javascript :: javascript remove certain element from array 
Javascript :: sequelize migration add column foreign key 
Javascript :: check if function javascript 
Javascript :: cypress ignore error 
Javascript :: how to use secondary color in material ui useStyle 
Javascript :: inject image javascript 
Javascript :: npm install global vs local 
Javascript :: how to split string into array javascript 
Javascript :: js remove property from object 
Javascript :: javascript array delete by index 
Javascript :: mongoose virtuals 
Javascript :: check date in between two dates nodejs 
Javascript :: Getting Binary gap in JS 
Javascript :: install nodemon 
Javascript :: generate random id javascript 
Javascript :: iframe chrome console 
Javascript :: select checked checkboxes javascript 
Javascript :: javascript string to float 
Javascript :: addclass to elementref angular 
Javascript :: make first letter capital 
Javascript :: vaidate youtube url 
Javascript :: how to get last item in array javascript 
Javascript :: loop through object in array javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =