jquery - Checking when all li's have been dynamically removed -
i've got function handles various types of behaviour property listing (my shortlist) <ul><li> setup. 1 type of behaviour removing property listing item <li> when click button within each item, that's working fine if statement check when items have been removed isn't working.
can tell me i'm doing wrong? here's part of function handles removing items via onclick event of button , dodgy if statement:
// remove item shortlist $(this).find('.btn-minus').click(function() { var btnremove = $(this); var proptile = $(this).parents('.property-tile'); var proplist = $('#property-listings'); // if ie 8 / 7 if ($('html').hasclass('lte8')) { proptile.hide('slide', 300, function() { btnremove.data("tooltip").hide(); }); } // other browsers else { proptile.fadeout(200, function() { btnremove.data("tooltip").hide(); $(this).remove(); }); } if (proptile.length === 0) { proplist.remove(); } }); and here's call function: $(".my-shortlist").myshortlist(); .my-shortlist <ul> element.
thanks
you have put '.property-tile' elements in variable, hiding them afterwards doesnt remove them objects variable. therefore need re-execute selector.
if ($(this).parents('.property-tile').length == 0) { proplist.remove(); } also, roger lindsjö mentioned, have problem of doing check before these elements hidden. need in callback of hide / fadeout.
Comments
Post a Comment