Page 1 of 1

onClick attr doesn't work on elements loaded via Javascript.

Posted: Mon Jun 29, 2009 6:48 pm
by Attilitus
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


This is only a problem for IE7. I'll explain with a psuedoexample:

Code: Select all

 
<div id="container">
<div style="height:25px; width:25px;" onClick="refreshDiv();"></div>
</div>
 
If you click that Div...

Code: Select all

 
<div id="container">
<div style="height:25px; width:25px;" onClick="refreshDiv();">Clicked 1 Time, try to click again</div>
</div>
 
If refreshDiv() updates the contents of "container" with an element that has an onClick attribute, then the onClick attribute will not work.

I imagine that the problem is that Internet Explorer processes all the events for elements on the page on the initial page load. I am using mootools, but for my specific needs it is much easier to just use the onclick attribute as I am iterating through a list and each element of the list needs unique parameters for the function. (But if I must I suppose I could generate the javascript code necessary to add event listeners to each element)

Does anyone know how to deal with this issue?


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: onClick attr doesn't work on elements loaded via Javascript.

Posted: Tue Jun 30, 2009 1:03 am
by VladSun
Post your javascript code, please