Hacker News new | ask | show | jobs
Don't use class names to find HTML elements with JS (follow-up w/ new metrics) (roytomeij.com)
2 points by roytomeij 5021 days ago
1 comments

Accessing the DOM is always slow in relative terms. In might not be applicable to everyone, but if you're accessing the DOM for view template purposes - I'd recommend using require.js with the text plugin instead.

And in all other cases, cache the jQuery object as early as possible in your module (i.e. assign `this.$targetEl = ...` in any init function you have ... so by the time you need to actually access/move/etc. that element, its already waiting for you.