JSFiddle - React, Tailwind, and code Playground
JavaScript
// two 'foo' nodes, one with text, one empty
var xmlData = '<thexml><foo node="foo">test1</foo><foo></foo></thexml>';
// load the string as DOM object
try { // IE
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = "false";
xml.loadXML(xmlData);
} catch (e) {
// all other browsers
var xml = new DOMParser().parseFromString(xmlData, 'application/xml');
}
// selects both foo nodes, alerts its contents
// first alert is test1, next is empty
$(xml).find('foo').each(function() {
alert($(this).text());
});