Opened 10 years ago
Closed 10 years ago
#13161 closed bug (invalid)
Inconsistant behavior for .append on <script> tag
Reported by: | Owned by: | ||
---|---|---|---|
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")
Change History (2)
comment:1 Changed 10 years ago by
Owner: | set to [email protected]… |
---|---|
Status: | new → pending |
comment:2 Changed 10 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
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!
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.