Obtaining the last inserted node.

Discussion in 'Javascript' started by Daz, Dec 25, 2006.

  1. Daz

    Daz Guest


    I would like to know how to obtain a reference to (or at least, element
    type of) the last node which was inserted into the document. I am using
    an event listener to listen for dom inserts, but I am not sure how to
    check if that last node was a script tag.

    Please could someone point me in the right direction?

    Many thanks, and Merry Christmas.

    Daz, Dec 25, 2006
    1. Advertisements

  2. If that is the W3C DOM Level 2 DOMNodeInserted event e.g.

    document.addEventListener('DOMNodeInserted', function (evt) {
    alert(evt.target + ' inserted under parent ' + evt.relatedNode);
    }, false);

    then the evt.target tells you the inserted node and evt.relatedNode the
    parent node into which evt.target has been inserted. So you can check
    whether evt.target is an element node and if so, its
    tagName.toLowerCase() is 'script'.
    Martin Honnen, Dec 25, 2006
    1. Advertisements

  3. Daz

    Daz Guest


    Thanks Martin. :)
    Daz, Dec 25, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.