GodsCrimeScene
GodsCrimeScene

Reputation: 1270

JQuery find works in IE but not Firefox

I am trying to pull values from an xml string using find from jQuery. It works in IE, but not in firefox.

I have the fiddle below:

var xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Template xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><templateId>90</templateId><CalendarColumn>MEASUREMENT_DATE</CalendarColumn><UOMColumn>undefined</UOMColumn><Type>dial</Type></Template>";

var catalogName = $(xmlString).find('CalendarColumn').text();

alert(catalogName);

http://jsfiddle.net/zJCfy/

If I run this in IE it will work correctly, displaying calendarColumn text. If I run this same fiddle in Firefox, I get "" returned.

JQuery shouldn't behave this way. Is this a browser settings issue?

Upvotes: 1

Views: 305

Answers (1)

tymeJV
tymeJV

Reputation: 104785

You have to parse that as XML first, and since you're using jQuery:

xmlString = $.parseXML(xmlString);

Demo: http://jsfiddle.net/zJCfy/1/

API: .parseXML : doc: http://api.jquery.com/jQuery.parseXML/

Upvotes: 5

Related Questions