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></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');
});
Try using live.