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

#7272
Zac Gordon
Keymaster

Yup. Like this:


var jon1, jon2, jon3;

jon1 = document.getElementsByClassName("content")[0];

jon2 = jon1.getElementsByTagName("article")[0];

jon3 = jon2.getElementsByTagName("a")[0];

console.log (jon3.innerHTML);

Notice that var is only used when declaring the variable, not when assigning it in this case.

You will see this method used a lot as you go forward 🙂