Whenever I try to unhide all the elements using the element queryselectorAll(), it says this
I don’t have anything undefined, and it still says that.
Whenever I try to unhide all the elements using the element queryselectorAll(), it says this
I don’t have anything undefined, and it still says that.
I might not have grasped what you want to achieve here, but something like this?
let button = document.querySelector(".start");
let answers = document.querySelector(".answers");
button.addEventListener("click", test);
function test() {
answers.classList.remove('hide')
button.classList.add('hide')
}
Hi @Growly, querySelectorAll()
doesn’t return a single element but a node list, which again doesn’t have a style
property – the contained elements do. So you should either
querySelector()
like for the start button, which will only return the first found element; orconst hidden = document.querySelectorAll('.hide')
// Then inside some other function
hidden.forEach(element => {
element.style.display = 'block'
})
I’d suggest to just remove hide
from the class list though, rather than overriding the CSS rule with inline styles…
hidden.forEach(element => {
element.classList.remove('hide')
})
(x-post)
querySelectorAll returns a node list. You would need to loop over that list to operate on each element in the list.
function test() {
hide.forEach(function(item) {
item.style.display = 'block';
});
button.style.display = "none";
}
Greetings fellow human from SitePoint, I’m having problems as always, tee hee.
I have done it this way
In which I grab all of the classes to which I assigned different names and put them into separate variables, not into one. Obviously this is a terrible idea as the syntax is too much! haha!
Haha! I have not thought of that. I forgot that existed!
I will do what you said.