“JavaScript Get Element nth Child” Kod odpowiedzi

Jak zdobyć 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 
uzii

JavaScript Get Element nth Child

//you can use the css nth-child property like this:
var second-child = document.querySeletorAll('[your element name]:nth-child(2)');
Wicked Warbler

Odpowiedzi podobne do “JavaScript Get Element nth Child”

Pytania podobne do “JavaScript Get Element nth Child”

Więcej pokrewnych odpowiedzi na “JavaScript Get Element nth Child” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu