how to modify this jquery syntax
- by Gandalf StormCrow
Hi all, this example below works when hover event is trigered and when its not, its working for elements already in DOM, but when element created dynamically it doesn't work, I realize I need to use jQuery live() or delegate() for this, the thing is I tried to modify it and its not producing the results as expected, here is the working code :
$(".sidebar li").hover(
function(){
$(this).css("background-color", "#F9F4D0");
$(this).append($('<button class="promoter" type="button" title="Active promotion"></button>'));
},
function(){
$(this).css("background-color", "#F9FAFA");
$(this).children("button").remove();
}
);
Here is the bit when I wanted to add live but it's not producing correct results :
$(".sidebar li").live('hover', function(){
$(this).css("background-color", "#F9F4D0");
$(this).append($('<button class="promoter" type="button" title="Active promotion"></button>'));
},
function(){
$(this).css("background-color", "#F9FAFA");
$(this).children("button").remove();
}
);
Where did I made mistake, thank you