Hi im adding some elements dynamically, now im trying to bind and a hover()
using on()
but that does not seem to work with a callback function. any ideas?
jQuery:
$(document.body).on('hover', 'div.settings-container', function () {
$(this).find('ul.settings-links').fadeIn();
}, function () {
$(this).find('ul.settings-links').fadeOut();
});
the jsfiddle is simplified.
This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element).
The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element. The onmousemove event triggers every time the mouse pointer is moved over the div element.
The hover() is an inbuilt method in jQuery which is used to specify two functions to start when mouse pointer move over the selected element. Syntax: $(selector). hover(Function_in, Function_out);
In jQuery, $(selector).hover(handlerIn, handlerOut)
is just a shortcut for
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
hover
is not an event, you need to use mouseenter
and mouseleave
instead.
$('body').on({
mouseenter: function() {
$(this).find('ul.settings-links').fadeIn();
},
mouseleave: function() {
$(this).find('ul.settings-links').fadeOut();
}
}, 'div.settings-container');
Method "on" uses "hover" as shortcut for both events - mouseenter and mouseleave use event.type to detect them
$(document).on('hover', 'a.hover-me', function (e) {
if (e.type == "mouseenter") {
alert("show");
} else {
alert("hide");
}
});
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With