Reputation: 1197
Based on an answer from the stack overflow post at: Change background color on mouseover and remove it after mouseout
the below code should set the css to display: block; on hover and display: none; when they hover off.
Can anyone see anything wrong with the below code? (No console errors are occuring) I'm basically trying to make myself a simple tool tip.
$(function () {
$(document).on('hover', '.inter [class]', function () {
$('._22t').css({
'display': 'block'
});
}, function () {
$('._22t').css({
'display': 'none'
});
});
});
Upvotes: 1
Views: 72
Reputation: 144659
on
doesn't accept 2 callback functions and apart from that you can't use hover
pseudo event name with the on
method:
Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string
"mouseenter mouseleave"
. It attaches a single event handler for those two events, and the handler must examineevent.type
to determine whether the event ismouseenter
ormouseleave
. Do not confuse the "hover" pseudo-event-name with the.hover()
method, which accepts one or two functions.
$(document).on('mouseenter mouseleave', '.inter [class]', function(event) {
$('._22t').toggle(event.type === 'mouseenter');
});
Upvotes: 7