Today while I was writing some code for two methods that shows and hides a menu, I made a small test to see the most efficient way to check the visibility of the menu.
The results varied from a browser to another, FF 4.0b12 is faster using $.data, but Chrome (webkit) and Opera is faster when using $.is(':visible').
I couldn’t test on IE9 , because the browser kept locking on me!
Here is the test case: http://jsperf.com/data-or-display/3
So, what’s the most efficient way to check visibility WITH jQuery ?
$('whatever').is(':visible')reads the best. I think that is what matters. Unless you need to check hundreds of elements a second, I would not waste my time.Donald Knuth
Source (PDF)
If you must get the best performance, ditch jQuery and use native JavaScript.