javascript - remove parent if no list element has children -
on website have list different classes maybe have content or not. if of them empty whole container should removed, if 1 or more have content inside, nothing should happen.
code snippets:
<div class="fts"> <div class="panel-heading">...</div> <div class="panel-collapse"> <div class="panel-body"> <div class=" bd-layoutbox-16 clearfix"> <div class="bd-container-inner"> <h5>heading 5</h5> <div>...</div> </div> </div> <div class=" bd-layoutbox-84 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-31 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-82 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-85 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-86 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-87 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-88 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-89 clearfix"> <div class="bd-container-inner"></div> </div> <div class=" bd-layoutbox-90 clearfix"> <div class="bd-container-inner"></div> </div> </div> </div> </div>
js
$(".bd-layoutbox-84, .bd-layoutbox-31, .bd-layoutbox-82, .bd-layoutbox-85, .bd-layoutbox-86, .bd-layoutbox-87, .bd-layoutbox-88, .bd-layoutbox-89, .bd-layoutbox-90") .each(function(){ if($(this).has("h5").length == 0){ $(this).parent().parent().parent().remove(); } });
what's problem?
thanks help.
you may need rework logic bit creating function, here's thought ..
var removethis=1; $(".bd-layoutbox-84, .bd-layoutbox-31, .bd-layoutbox-82, .bd-layoutbox-85, .bd-layoutbox-86, .bd-layoutbox-87, .bd-layoutbox-88, .bd-layoutbox-89, .bd-layoutbox-90") .each(function(){ if($(this).has("h5").length > 0){ removethis = 0; } }); if (removethis == 1) { // remove parent item here }
Comments
Post a Comment