简体   繁体   中英

How to get first element ID from XML in jQuery which works perfectly in IE

I have following XML in this.treeSpec variable.

<root>
    <item id="9PQ0" pathId="08Z" specId="9PQ0" rel="MainRequest">
        <content>
            <name>ABC</name>
        </content>
    <item id="9PQ02" pathId="08Z2X" specId="9PQ0" rel="property">
        <content>
            <name>ABC1</name>
        </content>
    <item id="9PQ02" pathId="08Z2" specId="" ruleId="CYZ3F7WM861" rel="E" >
        <content>
            <name>ABC2</name>
        </content>
    </item>

To get first item ID I am using below code.

var rootNode = $(this.treeSpec).find("item").first();
var rootId = rootNode.attr("id");

It works perfectly in Chrome and Mozilla but it is not working in IE.

Can any one tell me how can we write code to work in IE as well.

This might not be the actual solution, but try wrapping your xml in element like div and then try doing find, like:

$("<div>" + this.treeSpec + "</div>").find("item")...

Hope it helps

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