I get inconsistent results in browsers with the following test:
============= test.html ===========
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> </head> <body> <script> var xml; $.ajax({ type: "GET", url: "data.xml", success: function(data){ var node = $("CI:first", data); var query1 = $("T TX", node).length; var query2 = $("T", node).find("TX").length; var msg = '$("T TX", node).length: ' + query1; msg += "\n"; msg += '$("T", node).find("TX").length: ' + query2; alert(msg); } }); </script> </body> </html>
============= data.xml ============
<?xml version="1.0" encoding="ISO-8859-2"?> <CNs> <CI> <T> <TX></TX> </T> </CI> <CI> <T> <TX></TX> </T> </CI> <CI> <T> <TX></TX> </T> </CI> </CNs>
What is going to happen:
- Download xml via ajax call
- select xml node:
$("CI:first", data); - select node inside node:
$("T TX", node) - The second selection should contain only the tag "TX"
However, in IE6 and IE8 (not tried IE7), the second choice seems to ignore the "node" context and search for the entire XML document. The test runs as expected in FireFox and Safari. Executing this method works in IE $("T", node).find("TX") . Any explanation why $("T TX", node) not working in IE?
jquery
morgancodes
source share