Skip to main content

Bug Tracker

Side navigation

#6516 closed bug (fixed)

Opened May 03, 2010 03:08AM UTC

Closed April 17, 2011 05:15PM UTC

Last modified February 25, 2013 04:34AM UTC

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:
Description

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 (0.6 KB) - added by Phrogz May 03, 2010 03:10AM UTC.

    Desired Functionality

  • test_1.4.html (0.6 KB) - added by Phrogz May 03, 2010 03:10AM UTC.

    Failing Functionality

Change History (6)

Changed June 12, 2010 02:09AM UTC by dmethvin comment:1

component: unfiledcore

Changed November 12, 2010 02:40AM UTC by snover comment:2

milestone: 1.4.3

Resetting milestone to future.

Changed November 21, 2010 02:47AM UTC by addyosmani comment:3

priority: → 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.

Changed November 21, 2010 04:15AM UTC by snover comment:4

status: newopen
version: 1.4.21.4.4

Changed April 17, 2011 05:15PM UTC by timmywil comment:5

component: coremanipulation
milestone: → 1.5
priority: undecidedlow
resolution: → fixed
status: openclosed

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

Changed February 25, 2013 04:34AM UTC by kbates90 comment:6

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.