Skip to content

Ticket 10799#81

Closed
gibson042 wants to merge 3 commits intojquery:masterfrom
gibson042:bug_10799
Closed

Ticket 10799#81
gibson042 wants to merge 3 commits intojquery:masterfrom
gibson042:bug_10799

Conversation

@gibson042
Copy link
Member

document.getElementsByName doesn't behave as predictably as we'd all like it to. Sometimes, in quirks mode, IE limits the results to "form controls" (INPUT, SELECT, TEXTAREA, and other elements identified in HTML4 as ascribing meaning to the name attribute). When that is the case, jQuery("[name=*]") (which is optimized with getElementsByName) behaves even less predictably... it will include elements of any tag name if and only if there are no "form controls" matching the selector. I made a test case that showcases this absolutely bizarre IE behavior.

What's more, document.querySelectorAll does work as expected, so the quirky behavior is also dependent upon its definition and the presence or absence of pseudo-selectors. And although workaround selectors are easy to write, it's also easy to get tripped up by non-obvious method implementations: $current.has('[name=*]').

The bottom line is that we can only promise consistency by abandoning document.getElementsByName optimization of name selectors when it excludes elements from consideration. This pull request does precisely that.

@gibson042
Copy link
Member Author

Updated for smaller file size. getElementsByName is now only used if it does exactly what we want (and even then, only in the oldSizzle non-qSA fallback). The net effect on jQuery:

  249504   (+129) jquery.js
   93968    (-16) jquery.min.js
   33371     (-5) jquery.min.js.gz

Using getElementsByName calls that sweep up elements with matching ids seems to cost at least 30 bytes gzipped, more if we want to avoid slowdowns for browsers with sane implementations. And I'm pretty sure that every browser doing so also exhibits #10799 (limiting results to form controls and other HTML4-nameable elements), making such efforts pointless anyway.

@gibson042
Copy link
Member Author

Replaced by #113.

@gibson042 gibson042 closed this Jul 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant