Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery one() handler executed twice

I have a bug in my jQuery/animate.css code. The problem is an event handler that is called twice but it should be executed only one. You can find the code here, the important line is below:

JSFiddle

$('#tiles').addClass(tiles_in).one(animation_end, function() {
    // called twice
    log('tiles in');
});

In order to reproduce the bug, follow these steps:

  • Wait for the animation to end, which will output these logs
    • change_tiles
    • tiles out
    • tiles in
  • Click on the yellow div, here are the new logs
    • tile out // normal
    • tiles in // why ?

Tiles in should not be called again as the event is one(). And the documentation says "The .replaceWith() method removes all data and event handlers associated with the removed nodes." So I don't know.

like image 651
onda47 Avatar asked Aug 31 '26 08:08

onda47


1 Answers

why ?

A call to .one() is within first .one() event handler where the the event is attached to the same selector #tiles

like image 193
guest271314 Avatar answered Sep 02 '26 02:09

guest271314



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!