In jQuery, does it make sense to add selector context when specifying the ID? -


i found piece of code in jquery plugin:

$("#"+id,$t.grid.bdiv).css("display","none"); 

the second parameter $() changes context of search, right? still make sense include it, since line searching id? doesn't jquery search whole document when specifying id?

update:

@casablanca - sure calls native getelementbyid() ? because changed line document.getelementbyid('id').style.display = "none" , performance became faster (since line inside loop). tested using ie8 way.

it seems necessary. did quick test here anyway. finding is, jquery (unsurprisingly) doesn't care #id unique or not. in code:

alert($("#test", ".test2").html()); 

this returns within test2, correct, , if put:

alert($("#test").html()); 

i.e. without context, returns within test1

what guessing reason behind plugin writer mentioned, prevent used plugin , accidently use same id 1 using there. ensures no matter type in html, plugin works.

thanks finding. think include in authoring plugins.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -