Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove parent element jQuery
    primarykey
    data
    text
    <p>How can I remove all elements including its parent when click. The tabs is generated dynamically. What I tried so far is:</p> <p>I'm using bootbox for the confirmation.</p> <pre><code>function remove() { bootbox.confirm("Are you sure?", function(result) { if( result != false ) { var anchor = $(this).siblings('a'); $(anchor.attr('href')).remove(); $(this).parent().remove(); $(".nav-tabs li").children('a').first().click(); } }); } </code></pre> <p>The tab that I will remove is generated through this:</p> <pre><code>$(document).on('submit','#pop-form', function(e) { // make an ajax request $.post('../admin/FLT_add_tab.do', $('#pop-form').serialize(), function( data ) { // if data from the database is empty string if( $.trim( data ).length != 0 ) { // hide popover $('#popover').popover('hide'); //append new tab and new tab content var id = $(".nav-tabs").children().length - 1; $('#popover').closest('li').before('&lt;li&gt;&lt;a href="#tab_'+ id +'" data-toggle="tab" class="g-tabs"&gt;' + data + '&amp;nbsp;&lt;/a&gt;&lt;/li&gt;'); $('.tab-content').append('&lt;div class="tab-pane" id="tab_' + id + '"&gt; &lt;c:import url="flt-pis.html"&gt;&lt;/c:import&gt; &lt;/div&gt;'); } else { // error handling later here } } ); e.preventDefault(); }); </code></pre> <p><b>UPDATE: </b></p> <p><code>remove()</code> is called by appending <code>&lt;i&gt;</code> when the user hover the tab</p> <pre><code>$(document).ready( function() { $(document).on('mouseenter', 'a.g-tabs', function() { $( this ).append( $('&lt;i class="icon-clear-remove" onClick="tabRemove();"&gt;&lt;/i&gt;') ); }); $(document).on('mouseleave', 'a.g-tabs', function() { $( this ).find( ".icon-clear-remove:last" ).remove(); }); }); </code></pre> <p>The JS that concern if the page is refreshed</p> <pre><code>&lt;!-- Other tabs from the database --&gt; &lt;c:forEach var="tabNames" items="${ allTabs }"&gt; &lt;li&gt;&lt;a href="#tab_${ tabNames.value }" data-toggle="tab" class="g-tabs"&gt;${ tabNames.key }&amp;nbsp;&lt;/a&gt;&lt;/li&gt; &lt;/c:forEach&gt; </code></pre> <p>Popover for adding new tab</p> <pre><code>&lt;!-- Add new tab --&gt; &lt;li&gt;&lt;a href="#" id="popover"&gt;New &lt;i class="icon-plus-sign"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload