Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#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:
Blocked by: Blocking:


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 (4)

comment:1 Changed 13 years ago by dmethvin

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.

comment:2 Changed 12 years ago by dmethvin

Resolution: invalid
Status: newclosed


comment:3 Changed 11 years ago by anonymous

Not all script tags contain code... e.g. JQuery Templates

comment:4 Changed 11 years ago by anonymous


Jquery API seems to destroy jquery templates in lots of circumstances, if one wraps them in script tags as per the documentation, resulting in strange errors.

Note: See TracTickets for help on using tickets.