JavaScript for WordPress › Forums › Vanilla JavaScript › why use query selector › Reply To: why use query selector
June 8, 2016 at 3:48 pm
#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 of experience teaching in the classroom, leading workshops, giving talks and recording 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