Skip to content
Advertisement

querySelectorAll is not a function

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

Advertisement

Answer

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");
Advertisement