Using jquery for traversing XML - problem
Hi all!
I'm using jquery to traverse an XML nested in my HTML page. Don't ask why :)
I simply have a scenario when I have to deal with XML on client side
a lot. So, I figured I would use jquery for traversing and manipulating this XML. Everything works
perfectly fine with Firefox. But it fails for IE.
Consider this HTML:
- <div id = "mydiv">
- <p>
<span>
span 1
</span>
<span>
span 2
</span>
</p>
</div>
<div id= "xmldiv">
<node>
<subnode>
aaa
</subnode>
<subnode>
bbb
</subnode>
</node>
</div>
I realize that this HTML is invalid because of my custom tags. But like I said - this is what I have to deal with :). Unlike in the example above, I inject this XML dynamically on client side - but this is irrelevant.
This is the simplest jquery code used to select elements from DOM:
- $(document).ready(function() {
alert($("#mydiv p span").length);
alert($("#xmldiv node subnode").length);
});
In firefox - as expected I get 2 and 2 in alert window. However the jQuery under IE only selects the valid HTML tags and completely ingores my custom XML elements in the DOM. (I get 2 and then 0) Why?