Reputation: 2333
Is there anything wrong with this jQuery? The delay doesn't seems to work.
$( "#checked_value" ).replaceWith( "<div id='checked_value_loading'></div>").slideUp( 300 ).delay( 8000 ).fadeIn( 400 );
When I add in alert("test");
before the line of code, I can see it change to <div id='checked_value_loading'></div>
, but without the alert, there is no delay...
Upvotes: 1
Views: 318
Reputation: 262979
The problem is that replaceWith() returns the original set of elements, not the new one, so you are applying effects to elements that are not part of the DOM anymore.
A simple solution is to reverse your logic and use replaceAll() instead:
$("<div id='checked_value_loading'></div>")
.replaceAll("#checked_value")
.slideUp(300).delay(8000).fadeIn(400);
Upvotes: 2