Try to not suck at JavaScript. Store selected DOM elements for re-use

JavaScript is what all the cool kids use these days. Try not to totally suck at it.

We WordPress devs are probably a little late to the JavaScript club. If you’re like me, you’ve abused jQuery’s DOM selectors plenty. But it’s time to shape up. JavaScript is going to be doing more heavy lifting in the future. If you don’t stop sucking at JavaScript you won’t be able to do all the fun new things everyone’s doing.

The thing I’ve abused the most — and I’ve seen in other code a lot — is running back to jQuery’s DOM selector over and over. But selecting an element from the DOM can be pretty taxing. Whenever possible, you should save your DOM references so you don’t have to keep hitting that expensive selection routine.

10up’s Engineering Best Practices guide talks about this and other performance-saving JavaScript techniques.