Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  134] [ 1]  / answers: 1 / hits: 30908  / 9 Years ago, mon, october 12, 2015, 12:00:00

I am writing something in JavaScript that I need to use querySelectorAll.style but it always returns undefined, but it works perfectly with querySelector.style. How can I make it work properly so I can set the style?



document.querySelector(div#tabs + tabId + > div.page).style.display = 'none'; //works
document.querySelectorAll(div#tabs + tabId + > div.page).style.display = 'none';// doesn't work

More From » html

 Answers
8

querySelectorAll returns a list of elements rather than a single one.



So this should work to apply the style to the first element found:



document.querySelectorAll(div#tabs + tabId + > div.page)[0].style.display = 'none'; // First element

[#64766] Thursday, October 8, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nathalieg

Total Points: 462
Total Questions: 106
Total Answers: 93

Location: Turks and Caicos Islands
Member since Tue, Mar 30, 2021
3 Years ago
nathalieg questions
;