Bug Tracker

Opened 6 years ago

Closed 4 years ago

#10470 closed bug (fixed)

wrap() evaluates scripts

Reported by: nick@… Owned by: gibson042
Priority: low Milestone: 1.9
Component: manipulation Version: 1.6.4
Keywords: Cc:
Blocked by: #11795 Blocking:


Calling .wrap() will evaluate any scripts inside the element. This can cause problems when the browser has already run the scripts once. If this isn't considered a bug, it ought to be be mentioned in the documentation for wrap().

Workaround: manually do .remove('script') prior to using .wrap().

Demo: http://jsfiddle.net/nickh/BQRJt/

Change History (12)

comment:1 Changed 6 years ago by dmethvin

Status: newopen

comment:2 Changed 6 years ago by nick@…

Regarding the workaround, .remove('script') doesn't seem to work although .find('script').remove() does.

comment:3 Changed 5 years ago by nicholasbs

The only way I can think of to fix this is to add an optional argument to domManip (the function that wrap ultimately relies upon) and then do something like:

if ( !ignoreScripts && scripts.length ) {
  jQuery.each( scripts, evalScript );

Does this seem reasonable? If so, I'm happy to write a patch.

comment:4 Changed 5 years ago by pavol.eichler

Actually, it looks like wrap first reloads the script tags and only then removes them.

If you wrap an element containing a script element once, it is executed. You can now inspect the DOM and will find out the script element is missing. Thus, if you try to wrap the same element once more, the script is not executed.

Is there any reason to execute the scripts when the first wrap() is called, if it is always removed from the DOM by the same call?

Tested in FF 8, Chrome 15, jQuery 1.7.1 and jQuery 1.4.1

comment:5 Changed 5 years ago by dmethvin

Component: unfiledmanipulation

comment:6 Changed 5 years ago by mikesherov

Milestone: None1.8.2
Owner: set to mikesherov
Priority: undecidedlow
Status: openassigned

comment:7 Changed 5 years ago by mikesherov


comment:8 Changed 5 years ago by mikesherov

Blocked by: 11795 added

comment:9 Changed 5 years ago by mikesherov

Owner: changed from mikesherov to gibson042

comment:10 Changed 5 years ago by gibson042

#9134 is a duplicate of this ticket.

comment:12 Changed 4 years ago by Richard Gibson

Resolution: fixed
Status: assignedclosed

Fix #11795, #10470: keep scripts in DOM; execute only on first insertion. Close gh-864.

Changeset: e889134058232c5e19156353c5fc3bf3b4915a94

Note: See TracTickets for help on using tickets.