jquery - <ul> sub item count issue -
below code generated dynamically (between <li> </li>
) , removed.
<div class="popup-content"> <ul id="ulpopup" class="share-items-list"> <li> <div class="item-container"> <a href="#" class="close"></a> <span class="icon icon-kind-file icon-kind-pdf">pdf</span> <span class="item-title">notes last meeting</span> <a href="#" class="link-icon link-secondary icon-info-sign icon-medium"></a> </div> </li> <li> <div class="item-container"> <a href="#" class="close"></a> <span class="icon icon-kind-file icon-kind-doc">doc</span> <span class="item-title">legal , 401k info</span> <a href="#" class="link-icon link-secondary icon-info-sign icon-medium"></a> </div> </li> </ul> </div>
following jquery remove item.
$(document).on('click', '.close', function () { $(this).parent().remove(); var count1 = $('#ulpopup > li:visible').length; // way 1 var count2 = $("#ulpopup").children().length; // way 2 var ulid = document.getelementbyid("ulpopup"); // way 3 var count3 = ulid.children.length; alert(count1); });
whenever add / delete items count not pulling updated count.
please helpme out.
change $(this).parent().remove();
$(this).parents('li').remove();
remove list item containing close button
$(document).on('click', '.close', function () { $(this).parents('li').first().remove(); var count1 = $('#ulpopup > li').length; // way 1 alert(count1); });
Comments
Post a Comment