Hy there!
Is there any way to determine which element is currently hovered (by mouse) using jQuery?
Hy there!
Is there any way to determine which element is currently hovered (by mouse) using jQuery?
yes it is:
$("div.hover").hover( //select the elements you want to check the hover on, in this case i check all divs with the class hover
function(){ $(this).dosomething() },
function(){ $(this).dosomethingelse() }
)
$(this)
is the element that is acually hovered
here is an example that shows you how it works:
http://jsfiddle.net/hwhe7/
the second example makes an array of all elements you have hovered on your body: http://jsfiddle.net/mdH7L/
easiest way?
.bind()
a mouseover
or mouseenter
event to the document.body
and check the event.target
$(document.body).bind('mouseover', function(e){
console.log('currently hovering: ', e.target.id, 'tagName: ', e.target.tagName);
});
Reference: .bind(), mouseover, http://api.jquery.com/mouseenter/