Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: if mouseleave = true then DO THIS

Simple question, how would I accomplish this functionality in Jquery: Test whether the mouse is hovering over .myBox

    if ($(".myBox").mouseleave = true) {
        DO SOMETHING
    } else {something else}

OR

    if ($(".myBox").mouseover = false) {
        DO SOMETHING
    } else {Something else}

NOTE: im looking for an IF statement

like image 870
android.nick Avatar asked Dec 01 '22 03:12

android.nick


1 Answers

jQuery provides the is method for checking conditions with regard to a jQuery object. In your case you can check for the :hover CSS pseudo class:

$('.myBox').is(':hover') === true

Havre a look at this demo, try clicking the button (which will alert true) and the tabbing to and hitting enter on the button (without the mouse, it will return false).

DEMO: http://jsfiddle.net/marcuswhybrow/LL5JD/

like image 191
Marcus Whybrow Avatar answered Dec 04 '22 08:12

Marcus Whybrow