Bug Tracker

Ticket #7212 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

1.4.3 find() doesn't find elements when selecting from a form

Reported by: wolfsoft@… Owned by: john
Priority: blocker Milestone: 1.4.4
Component: selector Version: 1.4.3
Keywords: regression Cc:
Blocking: Blocked by:

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

comment:1 Changed 4 years ago by anonymous

P.S. Firefox 3.6.10 (Ubuntu Linux)

comment:2 Changed 4 years ago by addyosmani

  • Owner set to wolfsoft@…
  • Status changed from new to pending

Are you able to provide your complete original test case for us to evaluate?

comment:3 Changed 4 years ago by wolfsoft@…

  • Status changed from pending to new

Sure, here it is. Replace "1.4.3" to "1.4.2" and see the difference when pressing submit:

 http://jsfiddle.net/tebT7/

comment:4 Changed 4 years ago by snover

  • Keywords regression added
  • Priority changed from undecided to blocker
  • Status changed from new to open
  • Component changed from unfiled to selector

comment:5 Changed 4 years ago by rwaldron

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

Last edited 4 years ago by rwaldron (previous) (diff)

comment:6 Changed 4 years ago by snover

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 4 years ago by snover

  • Summary changed from 1.4.3 find() doesn't find anything to 1.4.3 find() doesn't find elements when selecting from a form

comment:8 Changed 4 years ago by snover

#7270 is a duplicate of this ticket.

comment:9 Changed 4 years ago by snover

  • Owner changed from wolfsoft@… to addyosmani
  • Status changed from open to assigned

comment:10 Changed 4 years ago by jeresig

  • Status changed from assigned to closed
  • Resolution set to fixed

Make sure that we aren't reading one of the bad expandos. Fixes #7212.

Changeset: 4fc86d5eb1d4eaa3efad77dc224271d254f491e4

comment:11 follow-up: ↓ 14 Changed 4 years ago by rwaldron

Documentation that this ticket is resolved in 1.4.4rc1

 http://jsfiddle.net/rwaldron/tVXZj/

comment:12 Changed 4 years ago by rwaldron

#7275 is a duplicate of this ticket.

comment:13 Changed 4 years ago by addyosmani

#7324 is a duplicate of this ticket.

comment:14 in reply to: ↑ 11 ; follow-up: ↓ 15 Changed 4 years ago by cybernetix@…

Replying to rwaldron:

Documentation that this ticket is resolved in 1.4.4rc1

 http://jsfiddle.net/rwaldron/tVXZj/

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 in reply to: ↑ 14 Changed 4 years ago by anonymous

Replying to cybernetix@…:

Replying to rwaldron:

Documentation that this ticket is resolved in 1.4.4rc1

 http://jsfiddle.net/rwaldron/tVXZj/

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 4 years ago by snover

  • Status changed from closed to reopened
  • Resolution fixed deleted

Please do not paste test code in tickets'''

 revised test case

Version 0, edited 4 years ago by snover (next)

comment:17 Changed 4 years ago by snover

  • Status changed from reopened to open

comment:18 Changed 4 years ago by snover

  • Owner addyosmani deleted
  • Status changed from open to assigned

comment:19 Changed 4 years ago by snover

  • Status changed from assigned to open

comment:20 Changed 4 years ago by dmethvin

  • Status changed from open to closed
  • Resolution set to duplicate

comment:21 Changed 4 years ago by dmethvin

Duplicate of #3113.

comment:22 Changed 4 years ago by dmethvin

  • Status changed from closed to reopened
  • Resolution duplicate deleted

I that that back, it's the same phenomenon but not the same code/solution.

comment:23 Changed 4 years ago by john

  • Owner set to john
  • Status changed from reopened to assigned

comment:24 Changed 4 years ago by rwaldron

#7351 is a duplicate of this ticket.

comment:25 Changed 4 years ago by anonymous

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:26 Changed 4 years ago by snover

#7356 is a duplicate of this ticket.

comment:27 Changed 4 years ago by jeresig

  • Status changed from assigned to closed
  • Resolution set to fixed

Only change ID on nodes that don't already have an ID for rooted qSA. Fixes #7212.

Changeset: 62c83a764cdb3f6e7f6a9b696de1636570df19bf

comment:28 Changed 4 years ago by snover

#7373 is a duplicate of this ticket.

comment:29 Changed 4 years ago by snover

#7384 is a duplicate of this ticket.

comment:30 Changed 4 years ago by addyosmani

#7407 is a duplicate of this ticket.

comment:31 follow-up: ↓ 32 Changed 4 years ago by jeff@…

Any word on a fix for this issue?

comment:32 in reply to: ↑ 31 Changed 4 years ago by jitter

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.

Last edited 4 years ago by jitter (previous) (diff)

comment:33 Changed 4 years ago by rwaldron

#7460 is a duplicate of this ticket.

comment:34 Changed 4 years ago by Richman777@…

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:35 Changed 4 years ago by rwaldron

#7738 is a duplicate of this ticket.

comment:36 Changed 4 years ago by rwaldron

#8507 is a duplicate of this ticket.

comment:37 Changed 4 years ago by rwaldron

#3113 is a duplicate of this ticket.

comment:38 follow-up: ↓ 39 Changed 4 years ago by 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.

 http://jsfiddle.net/aero2600/xv3KB/1/

comment:39 in reply to: ↑ 38 Changed 4 years ago by timmywil

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.

 http://jsfiddle.net/aero2600/xv3KB/1/

This bug has been fixed for 1.6, but this ticket is a duplicate of others currently open, such as #3113.

 http://jsfiddle.net/timmywil/xv3KB/5/

comment:40 follow-up: ↓ 41 Changed 4 years ago by timmywil

Sorry, I meant #3685.

comment:41 in reply to: ↑ 40 Changed 4 years ago by jcm@…

Replying to timmywil:

Sorry, I meant #3685.

Thank you for the heads up.

comment:42 Changed 4 years ago by soulshards

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.

Note: See TracTickets for help on using tickets.