JQuery mouseover function fires several times

I have been using this method for a long time to set events for all classes (for buttons, etc.):

$("div.bigButton").mouseover(function() { this.style.backgroundColor = '#dfdfdf'; });

However, while doing some testing, I just noticed that when you move the mouse over these objects, the function works 3 times! This is invisible when changing something like backgroundColor, but if I add a warning, it is very obvious.

Any ideas what I'm doing wrong? I am concerned that this may affect performance in the future.

thank

EDIT: Sorry, missing "style" was sealed

HTML:

<div class="bigButton">
Test</div>
+4
source share
3 answers

, , , ( , ajax). , "mouseover", , !

+2

- HTML-. jQuery ( mouseover mouseenter), , . http://api.jquery.com/mouseover/

+7

, .hover .mouseenter .mouseleave.

, , , .

Having tried this fiddle , I cannot reproduce your problem, so your problem lies in your HTML / JavaScript code. Maybe you attach the handle three times?

+2
source

Source: https://habr.com/ru/post/1544172/


All Articles