views:

121

answers:

2

I've recently upgraded an application from jQuery 1.2 to 1.3.2 - and we've found a rather strange regression.

For some html approximately like this (simplified a bit)

<div id="steps">
  <div class="step">
    <span>step #1</span>
    <div class="removeStep"> X </div>
  </div>
  <div class="step">
    <span>step #2</span>
    <div class="removeStep"> X </div>
  </div>
</div>

We previously attached an event like so, for all the steps:

$("#steps").find(".removeStep").click(removeStepFunc)

Under 1.2 this would find all the steps, even ones we dynamically added. Under 1.3 this only ever finds the first step.

This also doesn't work:

#("#steps .removeStep").click(removeStepFunc)

However, this does:

#("#steps).children().find(".removeStep").click(removeStepFunc)

I can obviously work around the issue, but It does make me a little nervous that perhaps there are other similar regressions affecting the application now we have upgraded, that will only present themselves in some cases when we have more then one element to match.

Also I see this other question, which I suspect might be the same issue?

http://stackoverflow.com/questions/969647/jquery-selector-bug-composed-selector-vs-simple-selector-find

A: 

Try the following:

jQuery('#steps > .removeStep').click(removeStepFunc)

or

jQuery('#steps .step .removeStep').click(removeStepFunc)
step #1 X step #2 X

UPDATE

What about something like this? (untested):

jQuery('#steps .removeStep').click( function() {
  jQuery(this).remove(jQuery(this).parent());
});
Steven
Unfortunately that doesn't work either, here's the results of testing:$("#steps > .removeStep") -> 0 matches$("#steps > .step > .removeStep") -> 1 match$("#steps div").find(".removeStep") -> 1 match$("#steps .step .removeStep") -> 1 match$(".step .removeStep") -> 1 match$(".step").find(".removeStep") -> 1 match$("#steps").children() -> 3 matches$("#steps").children().find(".removeStep") -> 3 matchesI don't believe the problem is jQuery, so much as it is some other library (possibly ExtJS?) interfering with jQuery's normal behaviour. This is a pretty fundamental part of jQuery :)
Bittercoder
If you put an alert inside `jQuery('#steps .removeStep').click`, and that alert triggers, your jQuery works fine. For testing, you could remove ExtJS and see if that helps.
Steven
A: 

Have now resolved this issue after stumbling across this post:

http://groups.google.com/group/jquery-en/browse_thread/thread/ae61896a809f6cf0

The problems were were experiencing were caused by our use of an old version of the jQuery Validator plugin (v1.3) that was incompatible with jQuery 1.3.2. The problem has been resolved now that we've updated it to v1.6.

Bittercoder