JavaScript for WordPress Forums Vanilla JavaScript why use query selector Reply To: why use query selector

#6195
Zac Gordon
Keymaster

Try starting with this markup:


  <div id="content">
    <div class="entry-content">
      <h1 class="entry-title">Zac Gordon</h1>
      <p>Zac Gordon is a professional educator with years&nbsp;of experience teaching in the classroom, leading&nbsp;workshops, giving talks and recording&nbsp;online courses.</p>
    </div>  
  </div>

and then try to do the equivalent of this


var header = document.querySelector( '#content .entry-content h1' ); 

using:

– getElementById
– getElementsByClassName
– getElementsByTagName