I have a div which contains several li elements. Each li has a close icon. Once you click on it, the entire li item related to it is then removed.
However, once all li elements have been removed, then div still remains. In my project, it has a background-color so when li elements have been removed, then empty div area is visible.
I have tried all options on this link, but none of them worked. Remove class when no inner elements exist
HTML code:
<div class="divArea">
<li class="li-item" id="li-item1">Item 1 <span class="icon icon-close
item-close" id="item-close1"></span></li>
<li class="li-item" id="li-item2">Item 2 <span class="icon icon-close
item-close" id="item-close2"></span></li>
</div>
Jquery code:
$( "#item-close1" ).click(function() {
$("#li-item1").remove();
});
$( "#item-close2" ).click(function() {
$("#li-item2").remove();
});
How can I make it that when the last li element has been removed, then div area will be removed as well?