JavaScript for WordPress Forums Vanilla JavaScript 1.3.04 – Traversing the DOM Reply To: 1.3.04 – Traversing the DOM

Zac Gordon

Hi Bonnie!

You raise a great question here and it really comes down to coding styles.

In general the WP coding standards like you to define things in variables before using and if you’re ever going to use something twice you definitely want to assign it as a variable.

That said, combining it all into one statement is completely valid. As we look at more advanced JS and stuff outside the WP community, like with the different frameworks you may see more of this style of combining calls into one line of code rather than several.

Hope this helps explain!!!