Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6417 closed bug (duplicate)

Script tags behave oddly when added to the document

Reported by: nsalyzyn Owned by: nsalyzyn
Priority: undecided Milestone: 1.4.2
Component: manipulation Version: 1.4.2
Keywords: script tag, append Cc: [email protected]
Blocked by: Blocking:


The following two jquery calls should have duplicate effects:

  $('<div>some text</div>')
  .append('<script type="other">something</' + 'script>')

   $('<div>some text</div>')
   .append('<script type="other">something</' + 'script>')

However, it produces the following dom:

  <div>some text</div>
  <script type="other">something</script>
  <div>some text<script type="other">something</script></div>

The second type of addition makes the most sense. This is important since javascript programs such as MathJax use script tags with other type fields to perform various actions.

Change History (5)

comment:1 Changed 13 years ago by nsalyzyn

I found the code responsible:

in jQuery.clean near the bottom of the function there is:

if ( fragment ) {
  for ( var i = 0; ret[i]; i++ ) {
    if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
      scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
    } else {
      if ( ret[i].nodeType === 1 ) {
        ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
      fragment.appendChild( ret[i] );

You use ret[i].getElementsByTagName("script"), but do not eliminate those that have blank or text/javascript type fields.

comment:2 Changed 12 years ago by Rick Waldron

Owner: set to nsalyzyn
Priority: undecided
Status: newpending

Please provide a reduced jsFiddle test case, thanks!

Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

comment:3 Changed 12 years ago by Rick Waldron

Keywords: needsreview added

comment:4 Changed 12 years ago by dmethvin

Keywords: needsreview removed
Resolution: duplicate
Status: pendingclosed

comment:5 Changed 12 years ago by dmethvin

Duplicate of #6941.

Note: See TracTickets for help on using tickets.