I disagree. jQuery should be smart enough to let people query as they see fit and optimize their selectors if they run into a problem. There are hundreds of permutations of "bad code." How should jQuery determine which ones are worthy of being "compensated for"? I think it's a very bad idea to have jQuery change what you're querying, as if somehow it would know better than you as a developer what you want to select. Seems awfully paternalistic to me.
Do you have any data on the "many jQuery developers" who are making this mistake? Or is it just a gut feeling?
Regardless of whether it's a recommended practice, a developer should be able to trust that using the context will behave as advertised. Besides, it's conceivable that in some situations tampering with the context would be break someone's site. Consider a site in which the same code is run on multiple pages. One group of pages has HTML that looks like this:
- <div id="section-a">
- <div id="jq-intro">
- </div>
- </div>
while another group has HTML like this:
- <div id="section-b">
- <div id="jq-intro">
- </div>
- </div>
If jQuery ignored the context, then the following selector would select the #jq-intro element on all of those pages instead of just the first group:
- $('#jq-intro', '#section-a')
And that would be bad.
--Karl