On Thu, Mar 17, 2011 at 5:32 PM, Matt Kruse <[email protected]> wrote:
> I have a reference to a DOM node. I want to know when it is removed
> from the document, even if it was caused by a PARENT node being
> removed!
> (Firefox 3.5+, Chrome, Safari, Opera, don't care about IE)
>
> I'll cover the obvious:
>
> 1) DOMNodeRemovedFromDocument: Doesn't bubble, and only fires on the
> actual element removed, rather than for all children.
>
> 2) DOMNodeRemoved: Bubbles, so I can attach at document level, but
> also doesn't fire on child elements
>
> 3) Catch one of the events above, then use querySelector() to see if
> my child element is contained in it. But I can't query on an object
> reference, so I would need a unique ID on the node, which I may not
> have
>
This (3) seems to me the best solution but use
"compareDocumentPosition()" method instead.
In this way you can use the references you have without performing an
extra query.
> 4) I can do querySelectorAll('*') and manually look through all the
> child nodes, but that seems so inefficient!
>
maybe you could use method 2 and "matchesSelector()" to avoid using an expensive
universal "*" selector if you need to match an object reference with a
selector string.
--
Diego
> Any suggestions?
>
> Matt Kruse
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]