I am utilizing the jQuery UI, the accordion specifically. I wanted to add a “remove” button to each accordion that would hide it.
My current code just sets the visibility to hidden on the div. But, I need to completely remove the accordion.
Here is how I have my html laid out.
<div class="my-accordion">
<h3>Accordion 1</h3>
<div>
<p>derp</p>
<div class="remove">REMOVE</div>
</div>
<h3>Accordion 2</h3>
<div>
<p>derp</p>
<div class="remove">REMOVE</div>
</div>
<h3>Accordion 3</h3>
<div>
<p>derp</p>
<div class="remove">REMOVE</div>
</div>
</div>
And, here is my jQuery.
$(function() {
$( ".my-accordion" ).accordion();
});
// This is a giant failure.
$('.remove').click(function(e) {
$(this).parent().hide();
e.preventDefault();
});
DEMO
To remove the parent
divuse.remove().OR in a row
DEMO
Note
It would be better if you can wrap each accordion within a
divwrapper like below:HTML
and change the jQuery code like: