0

I am trying to find elements inside an XML response from an AJAX call, but I'm finding that the tag names are a bit odd. These tags are causing problems with my selectors.

The XML element I'm looking for in particular is <d:Department>. Using jQuery in Chrome I can find this element with $(xml).find('Department'). jQuery can't find the element in IE.

Using JavaScript I can get the element in Chrome using xml.getElementsByTagName('Department'). In IE I have to use xml.getElementsByTagName('d:Department').

Is there a way to get this element in both browsers using JavaScript or jQuery without the need to look for both tag names?

DunningKrugerEffect
  • 603
  • 1
  • 5
  • 18

1 Answers1

1

Jquery:

What version of jQuery are you using?

Be aware of the current IE support:

  • jQuery 1.x Internet Explorer 6+
  • jQuery 2.x Internet Explorer 9+

Try including the namespace in the find method like so:

$(xml).find('d\\:Department');

This is explained in jQuery XML parsing with namespaces

Javascript:

Try to use getElementsByTagNameNS() like so:

xml.getElementsByTagNameNS("d", "Department");

see: http://www.w3schools.com/xml/met_document_getelementsbytagnamens.asp

Hope this helps!

Community
  • 1
  • 1
  • I was still having trouble with the same code working in Chrome and IE. This eventually got it to work the same way on both. `$(rawXml).find('d\\:Department, Department')`. – DunningKrugerEffect May 25 '16 at 13:23