Jquery selector strangeness is a bug, or am I doing it wrong?

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?

+6
jquery
source share
2 answers

My guess is a bug in jQuery code for: firstly. I remember that some time ago I saw how to get IE to allow the class pseudo-class with the first child, you need to have DOCTYPE. No doctype in XML ... so maybe that.

I would just switch from $ ("CI: first") to $ ("CI"). eq (0). $ ("CI") will give an array of all CI elements, and eq (0) will provide you with the first element.

+3
source share

This is mistake.

Filed at dev.jquery.com/ticket/4748 , upon request by John Resig .

+2
source share

All Articles