Opened 11 years ago
Closed 11 years ago
#11135 closed bug (cantfix)
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:
- Go to http://jsfiddle.net/nvmkf/
- Click "Run"
- Expected: "Inserted string" appears twice in the result
Observed: "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.
Change History (1)
comment:1 Changed 11 years ago by
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/