开发者

Selector regression after upgrade to jQuery 1.3.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?

jQuery selector bug? compos开发者_Go百科ed selector vs. simple selector & find()


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());
});


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜