views:

104

answers:

1

AddEventHandler in Javascript is for handling the events (like onclick) universally (i.e. on any element).

Is there a way to fire an event (don't know which kind) when a new element (i.e input, div, select, etc.) is being added to the page (through Ajax, jQuery, etc.)?

I've looked into the DOM documentation on dev mozilla but couldn't find anything. May be I'm not looking in the right pages.

+1  A: 

Is there a reason you want to know? If the reason is you want to add event handlers to new elements, you could use the "Live" functionality of jQuery instead.

Nosredna
Good to know about jQuery Live functionality. Thanks! Think if Google Analytics folks have to implement this functionality how they would pursue. Adding a new library (jQuery) won't be the case for them I think. Is there any other way that can be packaged with your existing js (without adding jQuery layer)?
Rac123
Sure. Just read up on event delegation in JavaScript. http://www.sitepoint.com/blogs/2008/07/23/javascript-event-delegation-is-easier-than-you-think/
Nosredna