Ticket #6558 (closed bug: invalid)
appendTo allows script tags to leak into the DOM
| Reported by: | arn_o | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | manipulation | Version: | 1.4.4 |
| Keywords: | append appendto head script | Cc: | |
| Blocking: | Blocked by: |
Description
In firefox 3.6.3 when I use
$('head').append('<script type="text/javascript" src="/src.js"></script>');
The script is loaded correctly but I can't retrieve this freshly added <script> tag in the list when I ask for it:
jsList = $("head > script[src][type='text/javascript']");
However I can retrieve it if I add it this way:
$('<script type="text/javascript" src="/src.js"></script>').appendTo('head');
or this way:
var e = document.createElement("script"); e.src = '/src.js'; e.type="text/javascript"; head.appendChild(e);
Shouldn't those three ways of adding a <script> tag to the <head> behave the same way ?
Change History
comment:2 Changed 3 years ago by snover
- Priority set to low
- Status changed from new to open
- Summary changed from different behaviour between $('head').append('<script ...') and $('<script...').appendTo('head') to appendTo allows script tags to leak into the DOM
- Version changed from 1.4.2 to 1.4.4
- Milestone set to 1.4.5
appendTo should not be appending the script tag.
comment:4 Changed 23 months ago by john
This has to do with how jQuery executes script tags - we remove script tags that we execute in order to not run them again, we need to the same here for the $("script").appendTo() case. Confirmed in triage.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Resetting milestone to future.