Bug Tracker

Modify

Ticket #11135 (closed bug: cantfix)

Opened 17 months ago

Last modified 17 months ago

clean() misbehaves for self-referencing scripts

Reported by: andrew_sayers Owned by:
Priority: low Milestone: None
Component: manipulation Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

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/
  2. Click "Run"
  3. 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

comment:1 Changed 17 months ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to cantfix
  • Status changed from new to closed
  • Component changed from unfiled to manipulation

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/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.