0

I have rows in a table containing buttons that when clicked, change the hover function of the tr element they are contained in. I just noticed that when I set the hover function it doesn't actually rewrite over the previous hover function, it just stacks on top of it. So when the hover event fires it calls the most recently set hover function as well as any previous ones that have been set. How can I reset the hover function each time I set it instead of stacking them?

secondbreakfast
  • 4,194
  • 5
  • 47
  • 101
  • 1
    That's the expected behaviour. You need to use `unbind` first in order to remove all previous handlers and then bind the new handler accordingly then. – Mohit Bhardwaj Jun 17 '16 at 12:27

1 Answers1

0

As Mohit Bhardwaj mentioned, the solution is to use the jQuery unbind method.

Note that simply calling $("#id").unbind("hover") will not work. It must be in the form of

$("#id").unbind('mouseenter').unbind('mouseleave')

or more simply

$("#id").unbind('mouseenter mouseleave');

How do I unbind "hover" in jQuery?

Community
  • 1
  • 1
secondbreakfast
  • 4,194
  • 5
  • 47
  • 101