The first is very fast, as jQuery internally uses getElementByIdwhen it recognizes a pattern (using a regular expression).
The second queries jQuery to iterate over all objects with an identifier. It is very slow. jQuery doesn't even stop the iteration when it finds one match in this case.
[id... , , , , "something", $('[id^=something]').
, HTML (no reused id) , $('#'+someId) ( -, Sizzle). $(document.getElementById(someId)).
: , "@" ID Sizzle ( jQuery) . Sizzle :
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|
/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/.test('#som@thing') false.
source
share