Which is better for website speed, CSS :hover or jQuery hover? Or are they about the same?
2 Answers
CSS
- CSS is native (built into browsers), like a HTML parser and a JavaScript engine
- CSS styles are exposed to scripting languages via the CSSOM - the CSS Object Model which defines APIs for media queries, selectors and CSS itself
- Implementation does not happen through a scripting language (unless the layout engine itself is written in one)
jQuery
- jQuery is a JavaScript library, and therefore external to browsers
- Needs to be downloaded and run through the browser's implementation of JavaScript
- jQuery will need to access the DOM and CSSOM, which is implemented in JavaScript, which the browser has to run
So, theoretically, while you can use jQuery and CSS to both use onEvent methods, CSS would be faster, as it is native to browsers, and does not have to do the added step to download and "translate" the library.
More information
Performance: Pure CSS vs jQuery
How browsers work - Behind the scenes of modern web browsers
:hoveris enough for you needs, why would you ever consider replacing it with jQuery?