Loading ...
Sorry, an error occurred while loading the content.
 

How to insert HTML element after/before another HTML element?

Expand Messages
  • ahbeng36
    Hi, May I know how to insert HTML element after/before another HTML element?
    Message 1 of 2 , May 1, 2007
      Hi,

      May I know how to insert HTML element after/before another HTML element?
    • andresm1981
      ... To insert an HTML element before, just use DOM s api method insertBefore: http://developer.mozilla.org/en/docs/DOM:element.insertBefore There is no DOM api
      Message 2 of 2 , May 2, 2007
        --- In ydn-javascript@yahoogroups.com, "ahbeng36" <ahbeng36@...> wrote:
        >
        > Hi,
        >
        > May I know how to insert HTML element after/before another HTML element?
        >

        To insert an HTML element before, just use DOM's api method insertBefore:

        http://developer.mozilla.org/en/docs/DOM:element.insertBefore

        There is no DOM api method for "insertAfter" but you should try this:

        function insertAfter(parent, node, referenceNode) {
        parent.insertBefore(node, referenceNode.nextSibling);
        }

        (Grabbed from Dustin Diaz's site:
        http://www.dustindiaz.com/top-ten-javascript )
      Your message has been successfully submitted and would be delivered to recipients shortly.