Skip to content Skip to sidebar Skip to footer

Fire Javascript Event On Object Creation

Is there any way to fire an event when an object of a certain type is created? I have an
element with editableContent='true' and when the user presses enter within the

Solution 1:

There are the a bunch of DOM Events and some of them will be supported by firefox for example. But I dont think that IE will support only one of them. Here is a complete list. First you can fire a custom event every time you create a new div, or you have a settimeout that checks every second if the count of you divs childnodes has changed.


Solution 2:

You have a function that creates a div when you press enter. Why don't you just add a function call at the end of it.

function createDiv(){
  //create div 
  //append div
  divCreated();
}

Solution 3:

There's no default callbacks for new elements creating. The first thing I have in mind - you can add an event listener for mouseUp event and check content delta (changed part) - if it looks like an element markup with regexp.


Solution 4:

Everybody who looking for a way to react to changes in a DOM should take into consideration MutationObserver. It is a standard DOM4 feature currently implemented in all latest (even not all modern but latest!) browsers.


Post a Comment for "Fire Javascript Event On Object Creation"