tags:

views:

65

answers:

1

I would like an element to receive an event and perform some action when it is injected into the DOM. Is there any event available to perform this?

Something like the following:

new Element('div', {
    events : {
       insertedIntoDom : function() {
         // Do something
       }
    }
})

Thanks

+1  A: 

There is no event that fires when an element is inserted into the DOM, but you can create custom events. After you create your event, you can fire the event after inserting the element.

VirtuosiMedia
@VirtuosiMedia - Mutation Events have been defined in DOM level 2. Not all browsers support them, but there is an event for dom insertions - `DOMNodeInserted` - http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mutationevents
Anurag
I stand corrected.
VirtuosiMedia