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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Attilitus
Forum Commoner
Posts: 27
Joined: Wed Aug 08, 2007 2:32 pm

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

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post by VladSun »

Post your javascript code, please
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply