For example sake, I’ll use some dummy code.
I have some jQuery setup that sends out an ajax request and replaces the html of a particular div with a div that has a class of “activate_tooltip”
The initial jQuery is sent out using
$('.button').live('click', function() {
//Ajax request goes out
//Div gets replaced with content like so
//$('.response_div').html('<div class="activate_tooltip"></div>');
});
I have a listener setup for the .activate_tooltip class, which for testing purposes, should send an alert to the window when hovered over. I used firebug to verify that the div content is getting added to the dom(and that the .activate_tooltip class is spelled correctly within the newly added div)… but hovering over the newly added div does nothing. The divs that already exist on the page, however, DO activate the alert when hovered over.
Any ideas?
Since you are adding the
divdynamically you should usedelegateoron(jQuery ver 1.7+) for events to work on dynamic elements. Try this.Using
delegateUsing
onIf you have the same behavior on
mouseoverandmouseoutevent then you can usehoverevent instead ofmouseover.References:
delegate()– http://api.jquery.com/delegate/on()– http://api.jquery.com/on/