Mouse hover works at first, but when I click remove button and attach it is not working with mouse hover handler?? why?
thanks.
HTML:
<div id="container">
<button id="a">remove</button><button id="b">attach</button>
<ul>
</ul>
</div>
JS:
var k = 10;
myfunction(k);
$('#a').click(function(){
$('ul li').remove();
});
$('#b').click(function(){
k = 20;
myfunction(k);
});
$('ul li').on('mouseenter',function () {
var num = $(this).index();
$('#lit' + num).addClass('currentpage');
$('#lit' + num).siblings().removeClass('currentpage');
});
function myfunction(p){
for(var i=0;i<p;i++){
$('#container ul').append('<li id=lit'+i+'>Hello'+i+'</li>');
}
}