Insert Tag Callback Events and Object Handles

Answered by: Karl Johan Kleist Last Updated: 2006-09-28

Does AOM lack an important feature?

=Question by N.N.=

I am successfully capturing insert_tag events using the appropriate callback, but do not know how to accomplish what I want done. I want to be able to insert an id attribute value upon insertion of certain tags. I know how to see what tag the user is inserting, but I do not know how to obtain a handle to a correspondiong DOM object which will allow me to set an attribute value and then have the open document reflect this.

I have tried insert_tag_after too, and I get the doc, the tagname, and the op. I don't want the doc, because that means I have to search, and I don't want to do that, especially against an element which has no name or id upon insertion. I just want the Node that was inserted, or which is about to be inserted, I'll take either. Brent Hartwig:

Can you depend on the caret telling you which node was inserted?

function InsertTagAfterCallback( doc, tagname, op ) { if ( op == 2 ) { local o = oid_current_tag( doc ); if ( oid_name( o ) != tagname ) { # assumption false. }   } }

=Karl Johan Kleist answers=

Looking at W3C Page on DOM Level 2 Events, it looks like you would want the MutationEvent where typeArg is DOMNodeInserted or DOMNodeInsertedIntoDocument. Comparing this to the AOM, I only see the DOMAttrModified and DOMCharDataModified events. Hard to believe AOM can't tell you when an element is inserted or removed. Moving on for now but am interested if someone has figured this out.