Bug Tracker

Modify

Ticket #5841 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 years ago by PSS

Trying some code formatting here...

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)

}); 

jQuery(document).ready(function() {

    jQuery('div#somethingelse').remove(); 
    content_text = jQuery('div#something').html(); 
    jQuery('div#something').after('<hr>' + content_text)

}); 

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#something').after('<hr>' + content_text)

}); 

comment:2 Changed 3 years ago by snover

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.