jquery queryselectorall code example

Example 1: class query css js all

var matches = document.querySelectorAll("div.note, div.alert");

Example 2: js queryselectorall

var container = document.querySelector("#test");
var matches = container.querySelectorAll("div.highlighted > p");

Example 3: js queryselectorall

var matches = document.querySelectorAll("p");

Example 4: javascript queryselectorall

<article class="article first">
  <div class="wrapper"> 
    <div class="oferts"> 
      <div class="pro"></div> 
      <h1>This is the Pro Version</h1>  
    </div>
    <div class="oferts"> 
      <div class="normal"></div> 
      <h1>This is the normal Version</h1>  
    </div>
  </div>
</article>


<!-- You will get a NodeList as Output -->
<!-- Try to do : console.log(typeof(oferts)) And you will see the type-->
<script>
var articleFirst = document.querySelectorAll("article.first");
console.log(articleFirst)
var oferts = articleFirst[0].querySelectorAll(".oferts");
console.log(oferts)
</script>

Example 5: select all elements javascript

var elements = document.getElementsByTagName("*");

Example 6: queryselector for jquery

var x = $(".yourclass")[0];
console.log('jq' + x);
var y = document.querySelector(".yourclass");
console.log('js' + y);

Tags:

Java Example