Skip to main content

Bug Tracker

Side navigation

#13161 closed bug (invalid)

Opened January 06, 2013 01:27PM UTC

Closed January 21, 2013 09:05AM UTC

Inconsistant behavior for .append on <script> tag

Reported by: otakustay@live.com Owned by: otakustay@live.com
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:
Description

I have a very simple script:

$('<script />')
    .attr('id', 'myScript')
    .attr('src', 'the-src-to-script')
    .appendTo('head');

For this code, I was expecting a <script> tag appended to <head> element with an id attribute of 'myScript', however jQuery lost the id attribute.

Dig into its source code, after the calling sequence "appendTo -> append -> domManip -> buildFragment", jQuery filters out all <script> tag to the "scripts" variable, and use .ajax method to load them, which certainly would create a new <script> tag without any custom attribute.

For this inconsistant behavior, is it possible that replace the .ajax call part, instead create a <script> element, merge all attributes to the new element, and then append it to a reasonable place.

By the way, this bug also puts the <script> element to a wrong place (as the first element of <head>, not the behavior of "append")

Attachments (0)
Change History (2)

Changed January 06, 2013 02:38PM UTC by dmethvin comment:1

owner: → otakustay@live.com
status: newpending

Please provide a complete jsfiddle.net test case using the work-in-progress version so we can evaluate this. Also, you might want to consider using $.getScript() if you just need to load a script.

Changed January 21, 2013 09:05AM UTC by trac-o-bot comment:2

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!