Removing jQuery Accordion Item
Asked Answered
D

2

6

How do you remove an item from a jQuery Accordion? I am trying to give the user the ability to delete an item from a database, displayed in an accordion, and have that item fade out after. I tried hiding the parent DIV of the item but the header remains and the accordion does not function properly after.

Here is the markup (basic accordion usage):

<div id="accordion">
<h3><a href="#">The Title - Item 1</a></h3>
<div>
The Content - Item 1
<a href="#" class="deleteItem">Delete</a>
</div>
<h3><a href="#">The Title - Item 2</a></h3>
<div>
The Content - Item 2
<a href="#" class="deleteItem">Delete</a>
</div>
</div>

Thanks!

Dupin answered 6/3, 2011 at 19:18 Comment(0)
O
12

assuming you're in the click event of a child of the content div, it would look something like this:

var parent = $(this).closest('div');
var head = parent.prev('h3');
parent.add(head).fadeOut('slow',function(){$(this).remove();});

here is a working example. not sure about the accordion not working afterword, but if it doesn't, try and re-initialize it.

Overanxious answered 6/3, 2011 at 19:23 Comment(2)
Thanks, works pretty well. I was surprised when I searched for a solution to find that either it isn't something that people commonly attempt. i did find one thread but it was never resolved. Thanks for your helpDupin
no problem. thats similar to how i've done it when necessary. seems like there should be a better way to build an accordion than using two completely unrelated elements like that, but i've never felt like making my own.Overanxious
E
0

If we have a condition like this then how do we delete the particular panel.and after deleting the panel with the help of Jquery i can call the servlet too.I tried alot but unable to do.Please help.

                 <% for(Entity result:pq.asIterable()) { 
                    String geeta=(String)result.getProperty("Title"); 
                    String fkey1 = result.getProperty("fkey").toString();

                        %>
                       <div class="container">
                           <div class="panel-group">
                             <div class='panel panel-default'>
                              <div class='panel-heading panelHeading'>
                 <input id ="org" type="hidden" name="key" value="<%=fkey1%>" /> 
             <h4 class='panel-title '>+&nbsp<%=geeta %><a class="close">&times;</a></h4>
                              </div>      
                     <div class='panel-body panelBody' style='display:none;'>
                    <a href="/update.jsp?key=<%=fkey1%>" target="blank"><h4><%=result.getProperty("Author") %></h4></a>
                     </div>
                   </div> 
                 </div> 
                </div>                     
                           <% }%>
Eugine answered 3/4, 2014 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.