Side navigation
#11135 closed bug (cantfix)
Opened January 06, 2012 04:23PM UTC
Closed January 06, 2012 05:12PM UTC
clean() misbehaves for self-referencing scripts
Reported by: | andrew_sayers | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | manipulation | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Tested in Firefox 9.0.1/Linux
Script tags of the form
<script class="foo">$(".foo")...</script>are a useful alternative to
document.write()when you want to e.g.
$(element).load()a document, but don't work because the
<script>tag is deleted while
$.clean()looks to execute it.
Steps to replicate:
1. Go to http://jsfiddle.net/nvmkf/
1. Click "Run"
1. Expected: "Inserted string" appears twice in the resultObserved: "Inserted string" only appears once
This seems to occur because
$.clean()doesn't include
<script>tags in the DocumentFragment it creates. I understand that
<script>tags need to be run separately from HTML insertion, but variants of
<script class="foo">$(".foo")...</script>are useful when e.g. a
$(element).load(...)needs to trigger some Javascript when the URL is inserted.
As well as running scripts explicitly, script tags should be included in the DocumentFragment so the script can refer to the tag it's in.
Attachments (0)
Change History (1)
Changed January 06, 2012 05:12PM UTC by comment:1
component: | unfiled → manipulation |
---|---|
priority: | undecided → low |
resolution: | → cantfix |
status: | new → closed |
The reason jQuery removes scripts and executes them manually is because it uses innerHTML whenever possible to inject new HTML. innerHTML disallows script tags: http://jsfiddle.net/rwaldron/kYsZj/