Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#6975 closed bug (worksforme)

$(document).ready() is called a 2nd time after calling nextUntil in combination wrap

Reported by: lmeurs Owned by:
Priority: Milestone: 1.4.2
Component: event Version: 1.4.2
Keywords: document ready head body nextUntill wrap Cc:
Blocked by: Blocking:

Description

When $(document).ready() is defined in the body, it's is called a 2nd time after nextUntil() is used in combination with wrap() or wrapAll().

When $(document).ready() is defined in the head or nextUntill() or wrap() is not used, $(document).ready() is only called once.

Take the attachment for example: in the beginning of the script one can choose to:

  • use $(document).ready(documentReady) or window.onload=documentReady
  • set $(document).ready(documentReady) or window.onload=documentReady in head or in body element

When you change either one of these variables, the script behaves as expected.

Tested in all major updated browsers.

Attachments (1)

jQuery.docReady.htm (958 bytes) - added by lmeurs 13 years ago.
Test file

Download all attachments as: .zip

Change History (3)

Changed 13 years ago by lmeurs

Attachment: jQuery.docReady.htm added

Test file

comment:1 Changed 13 years ago by dmethvin

Resolution: worksforme
Status: newclosed

Damn, you had me going there for a moment.

There are two <h1> elements in your document, so this line:

 $('h1').nextUntil('h1').wrap("<div style='background: red; ' />");

Selects both h1 elements and all the elements up until the next h1. That is basically the entire body! Since that includes the script in the body, the script is executed again in the process of wrapping the second h1 and its following content.

Whether .wrap() should re-execute script content that it wraps is another bug (I don't think it should and several related bugs are already open in the ajax component), but in the presence of that bug this code is working as intended.

comment:2 Changed 13 years ago by lmeurs

Oh man, sorry for the inconvenience! Your explanation makes sense, I always seem to forget a script-element is an actual HTML-element. Thanks for the effort, appreciate it!

Note: See TracTickets for help on using tickets.