Count the number of li's in a ul after some of the li's have had .remove() on them?
When you hit 开发者_如何学Cthe delete button a nice effect is run on that li and it is removed by using jquery's .remove() function. For some reason if i try to .size() on the parent ul it just still says the number of list items that were there when the page loaded?
update
var href = $(this).attr("href");
$(this).children(".deleteButton").fadeOut("fast");
$(this).parent("li").slideUp(300);
setTimeout("$(this).parent('li').remove();",300);
setTimeout("alert( $('ul.list').children().size());",300)
$.get(href);
return false;
This piece of code
setTimeout("$(this).parent('li').remove();",300);`
is conceptually wrong.
You expect $(this)
to be in closure but you are actually passing a string to the setTimeout callback.
So, when the callback is executed, $(this)
refer to window
(or document?? correct me plz)
You can put a callback to the slideUp
function you call, so that you remove that element after the slideUp
has terminated:
$(this).parent("li").slideUp(300, function (){ $(this).remove();});
SlideUp does not remove the element. It actually changes it's height and afterwards sets it's display to none.
Use a callback to remove the element.
$(this).parent("li").slideUp(300, function (){ $(this).remove();});
精彩评论