简体   繁体   中英

How to set the first child of `org.w3c.dom.element`?

I have a rootelment rootSVG of 'org.w3c.dom.element' class and I have a method which takes the sets the name of the script depending on the condition ,and creates a scriptelement and uses appendchild to insert that scriptelement as a child node for the rootelement.It sets the attribute("onload") of the root element and as this script.

But we know appendchild always inserts a node as the last child ,I want to know is there any mechanism that I can set this element as the first child node for the rootelement because in IE I get the message at times that the particular script is undefined when we load the page for the first time. Given below is the code snippet.

     if ( bEnableMouseEvents )
     {
        String scriptName = "SvgScriptUtils";            
        if ( !bUsingPlugin )
           scriptName = scriptName + "Native";
        // insert external javascript driver for tooltips/navigation-mode/popups            
        rootSVG.setAttribute("contentScriptType", "text/ecmascript");
        Element scriptElement = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_SCRIPT_TAG);
        scriptElement.setAttribute("type", "text/ecmascript");
        XlinkHref.set(scriptElement, "/scripts/" + scriptName + ".fs");
        rootSVG.appendChild(scriptElement);
        rootSVG.setAttribute("onload", scriptName + ".initMOS(evt)");           
     }    

Try Node.insertBefore(Node newChild, Node refChild) where refChild would be your currently first child (which, if you don't know it, you could get it by calling Node.getFirstChild() ).

For more information take a look at the javadoc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM