Q:

javascript queryselectorall


 var x =
 document.getElementsByClassName("example");

 
2
var matches = document.querySelectorAll("div.note, div.alert");
1
<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>
0
//Pretend there is a <p> with class "example"
const myParagraph = document.querySelector('.example');
//You can do many this with is
myParagraph.textContent = 'This is my new text';
5
/*The querySelector() method returns the first element that matches a specified 
CSS selector(s) in the document. Note: The querySelector() method only returns 
the first element that matches the specified selectors. To return all the 
matches, use the querySelectorAll() method instead.*/

// for example 

//for class
document.querySelector(".ClassName")

// for id 
document.querySelector("#ID")

// etc.
4
let x = document.querySelectorAll(".example"); 
2
var element = document.getElementById('element_id');
element.value = 'random_value';
0
//Get the first element in the document with class="example":
document.querySelector(".example");
/*
The querySelector() method returns the first element that matches a specified CSS selector(s) in the document.
Note: The querySelector() method only returns the first element that matches the specified selectors. To return all the matches, use the querySelectorAll() method instead.
If the selector matches an ID in document that is used several times (Note that an "id" should be unique within a page and should not be used more than once), it returns the first matching element.
*/

//example :
//https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_queryselector_class
0
document.querySelectorAll
-2

New to Communities?

Join the community