Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  168] [ 4]  / answers: 1 / hits: 123247  / 8 Years ago, wed, march 30, 2016, 12:00:00

I'm trying to find all oferts in the var articleFirst, but the return message in the console says that querySelectorAll is not a function. Why I do get that error?



This is my HTML:



<article class=first>     
<div class=feature parts>
<div class=oferts>
<div class=heart icons></div>
<h1>Build with passion</h1>
</div>
</div>
</article>


This is my JavaScript:



var articleFirst = document.querySelectorAll(article.first);
var oferts = articleFirst.querySelectorAll(.oferts);


Error:




Uncaught TypeError: articleFirst.querySelectorAll is not a function



More From » html

 Answers
21

Try do do this:


var articleFirst = document.querySelectorAll("article.first");
console.log(articleFirst)
var oferts = articleFirst[0].querySelectorAll(".oferts");
console.log(oferts)

With console you can see what is happening.


Or just do this:


document.querySelectorAll("article.first .oferts");

[#62756] Monday, March 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brynnleslis

Total Points: 425
Total Questions: 100
Total Answers: 115

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;