Bug Tracker

Modify

Ticket #11794 (closed bug: invalid)

Opened 12 months ago

Last modified 12 months ago

Injecting html with a name=xxx seems to corrupt a function with the same name

Reported by: ianmac Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

  1. create a function xxx
  1. inject some html with name=xxx [I'm using <form> but not sure if it's specific got <form> only]

function xxx works 1st time only. 2nd time I get a javascript error - xxx is not a function.

Both IE & FF have the problem, both IE & Firebug debuggers can see the original function and execute it.

sample code that reproduces it is here. if i rename the function tester() to another name it works. The 2nd click should give you the 'undefined function' error.

<html> <head> <script src="/admin/js/jquery.js" type="text/javascript"></script> <script> var seq = 0; function tester() {

seq++; $('#tester')[0].innerHTML = "<form name='tester'>I've been clicked ".concat(seq," time(s)</form>");

} </script> </head> <body>

<div id='tester'>tester div here</div> <a href='#' onclick='tester();return false'>click me 2 times</a>

</body> </html>

Change History

comment:1 Changed 12 months ago by ianmac

Live example is here:  http://dev.moditcms.com/test.html

comment:2 Changed 12 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

You have a name conflict, this is independent of jQuery.

 http://kangax.github.com/domlint/

Also I know it's just a demo but:

$('#tester')[0].innerHTML = ...

This will cause memory leaks if #tester has jQuery data or events.

onclick= ...

Inline event handlers are a bad idea.  http://docs.jquery.com/Won't_Fix#Inline_Event_Handlers

Last edited 12 months ago by dmethvin (previous) (diff)

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.