I am fairly new to JQuery API.
I have been using mouseover, but I have never used hover before.
SO I am wondering if I should use hover instead.
I am fairly new to JQuery API. I have been using mouseover, but I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well,
.hover()binds two handlers for the eventsmouseenterandmouseleave, so it is a more convenient way and also easier to understand the purpose.mouseenterdiffers frommouseoverso far asmouseenteris not fired if the cursor is over/enters a child element of the element the handler is bound to.It is only fired once, when the cursors enters the element.
mouseoveris always fired, even if the cursor is over a child element.The best way to see the difference is to have a look at the example of
mouseleave().Furthermore,
mouseoverandmouseoutare real JavaScript events whereasmouseenterandmouseleaveare events provided by jQuery (afaik).In the end, it depends on what you want to achieve. There is no right or wrong and all these methods have their purpose. Unless you show some code, there is not much more to say.
If you mean
:hoverin CSS and you can achieve the desired effect with it, go for it. If there is a non-JS solution for a certain problem, always choose this one.