I have many html tags with class = ‘class1’. They all happen to be/ and always will be the same type of element. For example input elements.
Is there a performance difference between
$("input.class1")
and
$(".class1")
Thanks!
NOTE: In this case i need information specifically pertaining to IE8, however a mention of a cross browser solution is important, my clients can only use IE8 so the best answer will have the best answer specifically for IE8.
Yes, there’s a performance difference. The latter allows the selector engine to use the native
getElementsByClassNamemethod that exists in most major browsers, and should be slightly faster in browsers that don’t support that method orquerySelectorAll. The former will be faster in browsers that supportquerySelectorAllbut notgetElementsByClassName(which is pretty much just IE 8), but likely still not as fast as the latter for your situation.For your scenario, use
$(".class1").