Home > Software engineering >  jquery hover not working after being moved
jquery hover not working after being moved

Time:05-09

I want to make a "catch the button game" so I have to move a button and if I move it the hover event doesn't work anymore. I tried it with normal js but that didnt help either.

CodePudding user response:

In the Case of the Dynamically added elements, It is better to add the event with the parent element. So you can use 'html' or 'body' tag for that.

.on(events[,selector][,data],handler)

$(document).ready(function () {
    $('html').on('hover', '.btnClass', function () {
        // do you work
    })
}); 

CodePudding user response:

Probably because you have a dynamic added element(button). Therefor you need to use the .on using jQuery. ✌️

$(".buttonClass").on("hover", function () {
// your function.
});
  • Related