Ticket #4385 (closed bug: invalid)
insertAfter loses script tags
| Reported by: | bryan_larsen | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | unfiled | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
If I clone some html that includes a script tag, the script gets cloned. However, if I then do an insertAfter() with that clone, the script tag gets lost.
Example (using jquery-1.3.2):
<div id="clone_me">
<script> ({option_a: 17}); </script> <span>Hello</span>
</div> <button onclick="jQuery('#clone_me').clone(true).insertAfter(jQuery(this));">
click me </button>
jQuery('#clone_me').clone(true).find('script').text() -> "({option_a: 17});" jQuery('#clone_me').clone(true).insertAfter(jQuery(this)).find ('script').text() -> ""
Tested with firefox 3.0.7
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Why do you want the actual script tag to remain? jQuery needs to be careful with leaving the script tags in because it doesn't want to execute the scripts multiple times.