Opened 13 years ago
Closed 12 years ago
#5841 closed bug (invalid)
Race condition (sync/async) bug in remove
Reported by: | PSS | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4.1 |
Component: | core | Version: | 1.4 |
Keywords: | remove html race | Cc: | |
Blocked by: | Blocking: |
Description
I have html
<div id ="something"> something something something something something something <div id="somethingelse">somethingelse</div> something something something something something something </div>
Then I slideToggle and then remove one div and copy parent contents to variable:
jQuery(document).ready(function() {
jQuery('div#somethingelse').slideToggle(1500, function () { jQuery(this).remove(); }); content_text = jQuery('div#something').html(); jQuery('div#something').after('<hr>' + content_text)
});
As result the variable content_text has data BEFORE slidetoggle + removal. Wrong.
This works:
jQuery(document).ready(function() {
jQuery('div#somethingelse').remove(); content_text = jQuery('div#something').html(); jQuery('div#something').after('<hr>' + content_text)
});
Is that as intended or a bug?
This does not work either:
jQuery(document).ready(function() {
var content_text = "nothing"; jQuery('div#somethingelse').slideToggle(1500, function () { jQuery(this).remove(); content_text = jQuery('div#something').html(); }); jQuery('div#somethingelse').remove(); jQuery('div#something').after('<hr>' + content_text)
});
Change History (2)
comment:1 Changed 13 years ago by
comment:2 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Thanks for the report, but this is not a jQuery bug. The callback passed to slideToggle
is executed asynchronously; this is how JavaScript works. You cannot do what you are trying to do. Please use the jQuery Forum for support requests.
Trying some code formatting here...