Hi there, for this code:
<div id="header">top of page</div>
<div class="message">hello, how are you</div>
<div class="message">I am fine</div>
$(document).ready(function()
{
$("#header").append('<div class="message">appended DIV</div>');
$('div.message').hover(
function() {
alert('hi');
},
function() {
alert('bye');
}
);
});
Why do the existing DIVs in the HTML trigger the mouse even and hence alert, but the appeneded DIV will not and is 'dead.' How can the appended DIV react like the existing ones?
thank you.
edit: in summary this was the solution:
$('<span />').addClass('message').text('(mouse 1)').appendTo('#header');
$('<span />').addClass('message').text('(mouse 2)').appendTo('#header');
$('.message').hover(
function() {
$('#header').prepend('in');
},
function() {
$('#header').prepend('out');
}
);
Note, if the SPANs are placed below the hover function, it won't work.