DOM javascript- add all elements as selected -
i working dom , when press key "i" elements should class "selected".
i cannot see why piece of code have written not working, please me.
my idea gather list of elements not have class selcted in "nodelist". once have that, loop through nodelist , each element add class "selected". in end want console.log how many elements selected. however, no part of code works! doing wrong?
thanks in advance.
if(keycode === 105) { nodelist = document.queryselectorall("not(.selected)"); for(i= 0; i< nodelist.length; i++) { place = nodelist[i]; place.classlist.add("selected"); } nodelist = document.queryselectorall(.selected); console.log(nodelist.length); }
i think problem use of not, pseudo selector, have used element selector(with wrong syntax)
if (keycode === 105) { nodelist = document.queryselectorall(":not(.selected)");//it pseudo selector (i = 0; < nodelist.length; i++) { place = nodelist[i]; place.classlist.add("selected"); } nodelist = document.queryselectorall('.selected');//also use string literal here console.log(nodelist.length); }
Comments
Post a Comment