PDA

View Full Version : DOM insertion events



moshe
13 May 2007, 2:50 AM
1) Is there any standard way I can listen for insertion of elements. I would like to create a function that automatically transforms all standard html tables and comboboxes when they are inserted.

2) would querying the DOM Tree at specified intervals looking for new elements be a performance problem i.e how quick is DOMQuery?

jsakalos
13 May 2007, 3:00 AM
Re 1: AFAIK not. Maybe I'm not fully grasping concept but if the insertion is taking place (I guess insertion is done from a js code) why not to call the applyTo directly as the next step?

Re 2: There is a thread with link to DomQuery performance tests. Search for it.

Animal
13 May 2007, 11:02 AM
I think Mozilla implements DOM mutation events. I experimented a little with them a while back. I'll have a look for my experimental code on Monday.

http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-eventgroupings-mutationevents

moshe
13 May 2007, 10:21 PM
jsakalos: I searched for the thread. but only found this one (http://extjs.com/forum/showthread.php?t=2348) but it doesn't mention any tests :(

Animal: Thanks :)

Animal
13 May 2007, 11:38 PM
It's as simple as



Ext.get(myElement).on("DOMNodeInserted", function(e) {
var be = e.browserEvent;
var t = be.target;
var r = be.relatedNode;
alert(t.tagName + "#" + t.id + " added to " + r.tagName + "#" + r.id);
});

jsakalos
14 May 2007, 4:10 AM
Re performance: Try to look here: http://www.jackslocum.com/blog/2007/01/11/domquery-css-selector-basic-xpath-implementation-with-benchmarks/

moshe
14 May 2007, 4:15 AM
thanks, I should have searched www.jackslocum.com as well, sorry