Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11794 closed bug (invalid)

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:
Blocked by: Blocking:

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 (2)

comment:1 Changed 7 years ago by ianmac

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

comment:2 Changed 7 years ago by dmethvin

Resolution: invalid
Status: newclosed

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 7 years ago by dmethvin (previous) (diff)
Note: See TracTickets for help on using tickets.