Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if mouse is over an element? (jQuery) [duplicate]

How to check if mouse is over an element?

I moving element to cursor position and I need to check if mouse is over an another element. How to do it?

<div class="dragged"></div> // I can move it
<div class="dropped"></div> // Need to drop here
$('.dragged').mousemove(function(e) {
   ...
   if($(".dropped").is(":hover")) { // of course doesn't work
        ...
   }
});

Thanks in advance.

like image 965
qwerty Avatar asked Jul 29 '14 09:07

qwerty


People also ask

How do you check if the mouse is over an element?

You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery.

What is difference between Mouseenter () and mouseover () event?

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.

What is Mouseout in jQuery?

jQuery mouseout() MethodThe mouseout event occurs when the mouse pointer leaves the selected element. The mouseout() method triggers the mouseout event, or attaches a function to run when a mouseout event occurs.

Is triggered when the mouse moves over an element?

mouseover: The onmouseover event triggers when the mouse pointer enters an element or any one of its child elements. mouseenter: The onmouseenter event is triggered only when the mouse pointer hits the element.


1 Answers

You may try like this:

$('#test').click(function() {
    if ($('#Test').is(':hover')) {
        alert('Test');
    }
});

JS FIDDLE DEMO

like image 128
Rahul Tripathi Avatar answered Sep 17 '22 18:09

Rahul Tripathi