Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  85] [ 4]  / answers: 1 / hits: 17810  / 13 Years ago, wed, july 20, 2011, 12:00:00

I would like to load data(via ajax) in a tooltip when the mouse is over a specific area. The problem is that the ajax call is made as long as my mouse is on that area. Is there any way, that I could make onmouseover (ajax call) efect happen just once? Here is the code:



$.post('calendar/event-details', {'eventId' :event.id},
function (data){
this.top = (ui.clientY + 15); this.left = (ui.clientX - 230);
$('body').append( '<div id=vtip>' + data + '</div>' );
$('div#vtip').css(top, this.top+px).css(left, this.left+px).fadeIn(slow);
$('div#vtip').css(position,absolute);
$('div#vtip').css(z-index, +99);
})

More From » jquery

 Answers
20

With .one:



$('element').one('mouseover', function() { /* ajax */ });


.one will detach the handler as soon as it is executed. As a result, it won't execute any more times.


[#91103] Monday, July 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
xiomara

Total Points: 378
Total Questions: 90
Total Answers: 104

Location: Guernsey
Member since Thu, Oct 7, 2021
3 Years ago
;