Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get the nth child of dom js

 //method one 
  var c = document.getElementById("myDIV").childNodes;
  c[1].style.backgroundColor = "yellow";//first child
  c[2].style.backgroundColor = "red";//second child
  c[-1].style.backgroundColor = "green";//last child
  c[-2].style.backgroundColor = "blue";//secound last child
//method two
 let nth-child = document.querySeletorAll('myDiv:nth-child(n)');//gives nth child 
Comment

javascript selector second element nth child element

var second-child = document.querySeletorAll('[your element name]:nth-child(2)');
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery once 
Javascript :: Download excel using reactJS 
Javascript :: how to make a grocery list in javascript 
Javascript :: unix timestamp js 
Javascript :: operators in js 
Javascript :: javascript module pattern 
Javascript :: html canvas not clearing 
Javascript :: uppercase-the-first-letter-of-a-string-using-javascript/ 
Javascript :: Factorialize a Number 
Javascript :: js date to timestamp 
Javascript :: vitejs env 
Javascript :: innerhtml 
Javascript :: ajax response length 
Javascript :: javascript select function 
Javascript :: javascript template literals html 
Javascript :: reverse a string while keeping spaces in javascript 
Javascript :: delete folder with deno 
Javascript :: prevstate in react 
Javascript :: Flatten a multidimension array 
Javascript :: replace character inside a string in JavaScript 
Javascript :: code for javascript message box 
Javascript :: object copy in javascript 
Javascript :: vue js count down timer 
Javascript :: node.js check if a remote URL exists 
Javascript :: SyntaxError: await is only valid in async function 
Javascript :: js how to calculate factorial 
Javascript :: js clearect 
Javascript :: how to use if else inside jsx in react 
Javascript :: DC League of Super-Pets 
Javascript :: remove from array javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =