HTML Code
<div id="foo">
<h1>foo</h1>
<p>Pellentesque habitant morbi tristique.</p>
</div>
<div id="bar">
<h1>bar</h1>
</div>
jQuery Code
$('#bar').click(function () {
$('#foo p').hide('slow').appendTo('#bar').show('slow');
})
Expected Result
When #bar is clicked
- hide the
p
element in#foo
- append
p
to#bar
- show
p
which is now a child of#bar
Actual Result
- append
p
to#bar
- hide the
p
element in#foo
- show
p
which is now a child of#bar
Questions
- What determines the execution order of methods in jQuery chains?
- How can I ensure that each event completes before the next starts?