Ticket #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: | |
| Blocking: | Blocked by: |
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
Change History
Changed 3 years ago by lmeurs
-
attachment
jQuery.docReady.htm
added
comment:1 Changed 3 years ago by dmethvin
- Status changed from new to closed
- Resolution set to worksforme
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Test file