I have selected a specific class via .querySelectorAll
:
var hit3 = document.querySelectorAll(".lattern.hit-3 .circle");
I am now trying to target and adjust a .style.visibility
attribut on this element, by doing the following:
hit3.style.visibility = "visible";
This however results in an error:
Uncaught TypeError: Cannot set property 'visibility' of undefined
How do I target a specific .style
with the above .querySelectorAll
selector?
querySelectorAll
returns an array like structure(NodeList) which does not have thestyle
attribute.But I think what you need is slightly different, I assume want to display the circle for the clicked element then
querySelectorAll
return a node list so you should specify the index of element you want to change :If you want to change the css of all the elements returned you should loop through them, see Johny's answer.
Hope this helps.