I’m trying to get an animation to work when I delete a section of an accordion. Instead of just disappearing, I’d like it to do something super duper cool. How do I get animate to work in this instance? Thanks a bunch. Here is my JS:
$('document').ready(function(){
$('#accordion .red').click(function(){
$(this).parent('div').prev( 'h3' ).remove();
$(this).parent('div').remove();
$(this).parent('div').prev('div').animate("bounceslide");
return false;
});
});
And here is my HTML:
<div id="accordion">
<h3><a href="#">Section 1</a></h3>
<div class="squares">
<a href="#" class="green">1</a>
<a href="# "class="red">2</a>
<a href="#" class="blue">3</a>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
<h3><a href="#">Section 1</a></h3>
<div class="squares">
<a href="#" class="green">1</a>
<a href="# "class="red">2</a>
<a href="#" class="blue">3</a>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
</div>
There’s a bit of a flaw in your logic as it currently stands…
You call:
And then:
Because
$(this)no longer exists in the DOM (it was removed along with its’ parent), your above selector won’t work.I would suggest using an animation callback to remove the accordion item after your super duper cool stuff.
Something like:
JSfiddle: http://jsfiddle.net/L9BXS/