Bug Tracker

Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#6516 closed bug (fixed)

replaceWith using DOM element with nested script does not run script

Reported by: Phrogz Owned by:
Priority: low Milestone: 1.5
Component: manipulation Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:


var div = $('<div><script type="text/javascript">alert("hi")<\/script><\/div>'); $('#foo').replaceWith( div[0] );

In jQuery 1.3.2, the above runs the code in the script block. In jQuery 1.4.2, the code is not run.

If you remove the [0], both 1.3 and 1.4 work. You can see test cases at http://phrogz.net/tmp/jquery_js_in_html/

Attachments (2)

test_1.3.html (650 bytes) - added by Phrogz 7 years ago.
Desired Functionality
test_1.4.html (650 bytes) - added by Phrogz 7 years ago.
Failing Functionality

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by Phrogz

Desired Functionality

Changed 7 years ago by Phrogz

Failing Functionality

comment:1 Changed 7 years ago by dmethvin

  • Component changed from unfiled to core

comment:2 Changed 6 years ago by snover

  • Milestone 1.4.3 deleted

Resetting milestone to future.

comment:3 Changed 6 years ago by addyosmani

  • Priority set to undecided

I can confirm that this issue is present with jQuery 1.4.2, 1.4.3 and 1.4.4, however as mentioned removing [0] does allow the original desired behavior to work Live Test Case.

comment:4 Changed 6 years ago by snover

  • Status changed from new to open
  • Version changed from 1.4.2 to 1.4.4

comment:5 Changed 6 years ago by timmywil

  • Component changed from core to manipulation
  • Milestone set to 1.5
  • Priority changed from undecided to low
  • Resolution set to fixed
  • Status changed from open to closed

It seems this bug is no longer present according to the test case provided by addy.

comment:6 Changed 4 years ago by kbates90

I see this issue with jquery1.7.2 - has this issue been fixed? I was seeing this issue in my script and moodified the above test script to use jquery1.7.2.js and replaceWith is not running script.

Note: See TracTickets for help on using tickets.