I am writing a simple hint:
$(function() {
$('a').hover(function() {
var curLink = $(this);
var toolTipText = curLink.attr('title');
if (toolTipText)
{
var theOffset = curLink.offset();
$('body').prepend('<div id="toolTip">'+toolTipText+'</div>');
$('#toolTip').css({
'left' : theOffset.left+'px',
'top' : theOffset.top - 30+'px'
});
}
}, function() {
$('#toolTip').remove();
});
});
As you can see, the div with the identifier "toolTip" is dynamically added to the DOM when the user hovers over the link. This div does not exist initially when the DOM is loaded, but added later. Therefore, I suggested that I should use the function live()and attach an event to it. But some how it works if I just see it as a regular selector. Not that I complained, but how does it work?
source
share