Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#7247 closed bug (fixed)

function bound to ready event fires twice on 1.4.3

Reported by: dustymugs Owned by: gf3
Priority: blocker Milestone: 1.4.4
Component: core Version: 1.4.3
Keywords: regression Cc:
Blocked by: Blocking:

Description (last modified by rwaldron)

I'm currently using Firefox 3.6.10 and Opera 10.60 on Slackware Linux 12.1.

In jQuery 1.4.2, a function bound to the document ready event fires once. The same is not true in 1.4.3. A simple test case can be found at:


For the test case above, the jquery version number should appear only once. It shows up twice for 1.4.3.

Change History (17)

comment:1 Changed 6 years ago by snover

  • Component changed from unfiled to core
  • Keywords regression added
  • Milestone changed from 1.5 to 1.4.4
  • Priority changed from undecided to blocker
  • Status changed from new to open

comment:2 Changed 6 years ago by cowboy

$(document).bind( 'ready', fn ) not only double-fires, but bound handlers also execute out-of-order. Note that $(document).ready( fn ) and $( fn ) seem fine.


comment:3 Changed 6 years ago by jitter

Confirmed in Opera 10.63, FF 4.04b, FF 3.6.10, Chrome and IE6 on Windows XP.

All show the same behavior. "ready bind bind" for snovers test case and the same order cowboy documented on his test-case

comment:4 Changed 6 years ago by alexsuper_chang@…

I use $(function(){}); in ie 7.0, the ready event is also double fires.

But sometimes OK, sometimes fail...the only way is back to v1.4.2....

comment:5 Changed 6 years ago by snover

  • Owner set to gf3
  • Status changed from open to assigned

comment:6 Changed 6 years ago by jeresig

  • Resolution set to fixed
  • Status changed from assigned to closed

Make sure that the ready event doesn't double-fire when .bind(ready) is used. Fixes #7247.

Changeset: 3df41db0369cfaf0fc229c633eb87f222ad49357

comment:7 Changed 6 years ago by john

Will deal with the out-of-order events over here: #7279 (that was an issue in 1.4.2 and earlier as well - it will require a lot more work, should go into 1.5, probably).

comment:8 Changed 6 years ago by snover

#7310 is a duplicate of this ticket.

comment:9 Changed 6 years ago by anonymous

I've tried apply the changes from the changeset to my code, but the event still fires twice.

In fact, before applying it it would seem to sometimes fire twice, and afterwards it is always firing twice.

I have tried both $(document).ready and $(document).bind('ready'

Is there anything I am doing wrong?

comment:10 Changed 6 years ago by rwaldron

  • Description modified (diff)

comment:11 Changed 6 years ago by anonymous

OK, I tried with that, and it still happened.

But then I played around a bit more, and it seems the problem was I was using an alert to check if it fired twice, and I kept getting two alerts. I switched to using console.log and only one message was logged. I combined both, so had an alert and a log in the handler, and got two alerts and two logs to the console.

So, it seems it is the alert that is causing the problem for me. I guess because it holds up execution of the handler, so the unbind doesn't happen until the alert is called.

I'm new to jQuery, so don't know enough of the inner workings to know if there is a clever workaround for this. Although, I've also only just discovered console.log, and so will probably be using that instead of alert from now on anyway, so may not encounter the problem again.

comment:12 follow-up: Changed 5 years ago by nAS

I can confirm the bug still remains in IE 6-9 (in IE8 always) Sample: http://pastebin.com/sa2Ays8M

comment:13 in reply to: ↑ 12 Changed 5 years ago by stefano788@…

Replying to nAS:

I can confirm the bug still remains in IE 6-9 (in IE8 always) Sample: http://pastebin.com/sa2Ays8M

i confirm bug with jquery 1.4.4rc2

comment:14 Changed 5 years ago by jitter

I can't reproduce this on IE6.

jsfiddle test case

comment:15 Changed 5 years ago by anonymous

Bug confirmed in Safari 5.0.3.

comment:16 Changed 5 years ago by anonymous

The bug seems to happen only when alert() is used in the callback. When logging is used it gets executed only once - exactly as stated above.

Furthermore, it does not matter whether we use $(function () {}) or $(document).ready(function (){}).

comment:17 Changed 5 years ago by pedro.dagraca@…

I seem to be having the problem even if I do not use alert. But it does not happen on all instances of $(document).ready and $(function().

Note: See TracTickets for help on using tickets.