Bhasim
Bhasim

Reputation: 1

jquery hover not working after being moved

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.

Upvotes: 0

Views: 50

Answers (2)

Abhishek Srivastava
Abhishek Srivastava

Reputation: 99

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
    })
}); 

Upvotes: 1

Kip
Kip

Reputation: 513

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

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

Upvotes: 0

Related Questions