#7212 closed bug (fixed)
1.4.3 find() doesn't find elements when selecting from a form
Reported by: | Owned by: | john | |
---|---|---|---|
Priority: | blocker | Milestone: | 1.4.4 |
Component: | selector | Version: | 1.4.3 |
Keywords: | regression | Cc: | |
Blocked by: | Blocking: |
Description
$(".message-delete-form").submit(function() { var form = $(this); alert(form.find("input[name='id']").length); });
This code displays "0" with 1.4.3 and correct value "1" with 1.4.2. So I rolled back to 1.4.2 temporarily.
Change History (42)
comment:1 Changed 8 years ago by
comment:2 Changed 8 years ago by
Owner: | set to wolfsoft@… |
---|---|
Status: | new → pending |
Are you able to provide your complete original test case for us to evaluate?
comment:3 Changed 8 years ago by
Status: | pending → new |
---|
Sure, here it is. Replace "1.4.3" to "1.4.2" and see the difference when pressing submit:
comment:4 Changed 8 years ago by
Component: | unfiled → selector |
---|---|
Keywords: | regression added |
Priority: | undecided → blocker |
Status: | new → open |
comment:5 Changed 8 years ago by
If you change name="id" to name="foo" this bug resolves itself. See: http://ejohn.org/blog/deadly-expandos/
Consider this a "well known gotcha". Note, this was addressed by myself and Rebecca Murphey
comment:6 Changed 8 years ago by
Fails in Firefox, and causes an Error to be raised in IE8. Works in Chrome, Opera, and Safari. Using common DOM words for input
name or id attributes is inadvisable, but this should still work as it did in 1.4.2.
comment:7 Changed 8 years ago by
Summary: | 1.4.3 find() doesn't find anything → 1.4.3 find() doesn't find elements when selecting from a form |
---|
comment:9 Changed 8 years ago by
Owner: | changed from wolfsoft@… to addyosmani |
---|---|
Status: | open → assigned |
comment:10 Changed 8 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Make sure that we aren't reading one of the bad expandos. Fixes #7212.
Changeset: 4fc86d5eb1d4eaa3efad77dc224271d254f491e4
comment:11 follow-up: 14 Changed 8 years ago by
Documentation that this ticket is resolved in 1.4.4rc1
comment:14 follow-up: 15 Changed 7 years ago by
Replying to rwaldron:
Documentation that this ticket is resolved in 1.4.4rc1
Firefox issue still persists.
This will work: console.log($("form").find("#id").length);
but this will not work: console.log($("#frm").find("#id").length);
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.4.4rc1.min.js" charset="utf-8"></script> <script type="text/javascript"> $(function(){ console.log($("form").find("#id").length); console.log($("form").find("[name=id]").length); console.log($("form").find(".cls").length); console.log($("#frm").find("#id").length); console.log($("#frm").find("[name=id]").length); console.log($("#frm").find(".cls").length); }); </script> <form id="frm" name="frm"> <input id="id" name="id" value="0" type="hidden" /> <input class="cls" id="f1" name="f1" value="" type="text" /> </form>
comment:15 Changed 7 years ago by
Replying to cybernetix@…:
Replying to rwaldron:
Documentation that this ticket is resolved in 1.4.4rc1
Firefox issue still persists.
This will work: console.log($("form").find("#id").length);
but this will not work: console.log($("#frm").find("#id").length);
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.4.4rc1.min.js" charset="utf-8"></script> <script type="text/javascript"> $(function(){ console.log($("form").find("#id").length); console.log($("form").find("[name=id]").length); console.log($("form").find(".cls").length); console.log($("#frm").find("#id").length); console.log($("#frm").find("[name=id]").length); console.log($("#frm").find(".cls").length); }); </script> <form id="frm" name="frm"> <input id="id" name="id" value="0" type="hidden" /> <input class="cls" id="f1" name="f1" value="" type="text" /> </form>
Also this will not work:
console.log($("[name=frm]").find("#id").length); console.log($("[name=frm]").find("[name=id]").length); console.log($("[name=frm]").find(".cls").length);
comment:16 Changed 7 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Please do not paste test code in tickets'''
comment:17 Changed 7 years ago by
Status: | reopened → open |
---|
comment:18 Changed 7 years ago by
Owner: | addyosmani deleted |
---|---|
Status: | open → assigned |
comment:19 Changed 7 years ago by
Status: | assigned → open |
---|
comment:20 Changed 7 years ago by
Resolution: | → duplicate |
---|---|
Status: | open → closed |
comment:22 Changed 7 years ago by
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
I that that back, it's the same phenomenon but not the same code/solution.
comment:23 Changed 7 years ago by
Owner: | set to john |
---|---|
Status: | reopened → assigned |
comment:25 Changed 7 years ago by
I'm experiencing the same issue.
This is a very serious issue. Especially for those whom rely on jQuery for development and use google APIs (and setting the script to fetch the latest update).
comment:27 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Only change ID on nodes that don't already have an ID for rooted qSA. Fixes #7212.
Changeset: 62c83a764cdb3f6e7f6a9b696de1636570df19bf
comment:32 Changed 7 years ago by
Replying to jeff@…:
Any word on a fix for this issue?
This has already been fixed. You can see that by looking near the start of the page where it says
(closed bug: fixed)
Also check comment 27 where John set the ticket to fixed and provides a link.
comment:34 Changed 7 years ago by
This change seems to cause strange behavior for invalid HTML where there is an id attribute with a space in it. This isn't a problem if the id is properly formatted and doesn't have a space.
If an element has a space in the ID (it was being auto-generated on our side and it wasn't supposed to have one...but it did) then the find() won't return a successful result on a subset of the children nodes. In our specific case, a parent TD node had an id="FIRST SECOND" (example) and then the children of that cell was a table with a row and 3 cells. Even though I wasn't using the id attribute in the traversing or selecting of any elements, trying to find() the first child cell of the TD with the invalid ID attribute would always return an empty result.
However, I could do a find() for the second and third cells and they would return the correct elements.
comment:38 follow-up: 39 Changed 7 years ago by
I do not believe this bug has been fixed. It is possible that I am not understanding the definition of 'fixed'. This bug still exists in Firefox, including Firefox 4, but does not occur in Chrome.
comment:39 Changed 7 years ago by
Replying to jcm@…:
I do not believe this bug has been fixed. It is possible that I am not understanding the definition of 'fixed'. This bug still exists in Firefox, including Firefox 4, but does not occur in Chrome.
This bug has been fixed for 1.6, but this ticket is a duplicate of others currently open, such as #3113.
comment:41 Changed 7 years ago by
comment:42 Changed 7 years ago by
I reached this bug report as I experienced odd jquery behavior resulting in returning broken element identifiers (selectors). The bug was experienced on both Linux and Windows OS, respectively using browser FF 3.6.17 and FF 4.0.1
Jquery versions tested with are 1.4.2 and current 1.6.1 as of this comment.
Example of what I define as corruption/bug is available here: http://jsfiddle.net/98ZX9/
I tend to assume that the corruption I experienced is either related or as a result of the issue this bug report is referring to.
P.S. Firefox 3.6.10 (Ubuntu Linux)