开发者

click() not registering on an element previously created by jQuery

I'm trying to hide() an element that was just created by a click() somewhere else on the page. Other elements that existed on page load will register the click and be hidden fine, but elements created after the page load will not.

Here I'm creating a new element with text in it from another element that is being hidden:

$("#cloud li").click(function(){
    var cat = "<li class='item'>"+$("a", this).text()+"<div class='action'><div class='close'></div></div><开发者_如何学Python;/li>";
    $("#left ul").append(cat);
    $(this).remove();
});

And here I'm trying to hide the element that was just created:

$('.item .action .close').click(function(){
    $(this).parent().parent().removeClass('active').fadeOut('fast');
});


$("#cloud li").click(function(){
    var cat = "<li class='item'>"+$("a", this).text()+"<div class='action'><div class='close'></div></div></li>";
    $("#left ul").append(cat);
    $(this).remove();
});

$('.item .action .close').live('click', function(){
    $(this).parent().parent().removeClass('active').fadeOut('fast');
});

Try using live.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜