Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector - what is faster?

$('#content td#foo').show(); $('td#foo').show();

The td is somewhere deep in the content div.

What is faster?

like image 501
christianhaller Avatar asked Mar 01 '10 13:03

christianhaller


People also ask

Which selector is faster in jQuery?

ID and Element selector are the fastest selectors in jQuery.

Which selector is faster ID or class?

Locating elements by id is faster than css. Because : id of an elements is more specific than css of an element.

Which CSS selector is faster?

popupbutton is the fastest.

Which is faster jQuery (# id or jQuery div id?

$("#myId) The document. getElementbyId( "myId") is faster because its direct call to JavaScript engine. jQuery is a wrapper that normalizes DOM manipulation in a way that works consistently in every major browser.


1 Answers

You can simply write

$("#foo").show();

You cannot have more than 1 elements with the same id. So no need to use any additional selector to get an element with a particular id. So your td tag selector can be avoided.

like image 140
rahul Avatar answered Sep 29 '22 05:09

rahul