Not detecting element after adding new object
Hey,
I hope anyone here can help me out. Basically what i am trying to do is that i have a unordered list and basically destroys the new list and creates a new one. The problem is that each element of that list has a hover event method. After the new list is created, the hover event is not detected. Any help is appreciated.
Here's the sample code:
-
// clear list function
$("#clear").click(function(){
$(".tlist ul").html("");
var list = "";
var data = [0, 1, 2, 3];
$(data).each(function(){
list += "<li id=\""+this+"\">" + this + "</li>";
});
alert(list);
$(".tlist ul").html(list);
});
// hover function
$(".tlist li").hover( function(){
alert('hovered');
});