I have a script that accepts XML input, and I want to convert it to JQuery object so that I can traverse it easily.
This is the code I use:
var xmlInput =
'<content>'+
'<action xsi:type="number">'+
"123"+
'</action>'+
'</content>';
var object = $(xmlInput);
alert(object);
alert(object.html());
object.find("action").each(function() {
var type = $(this).attr("xsi:type");
alert("action! type="+type);
});
(available online here:
http://irsrv2.cs.biu.ac.il:8080/GeniusWeb/jqueryTest.html )
This works fine in Firefox and Chrome:
- the first alert shows “object”,
- the second alert shows the inner “action” element,
- and a third alert shows “action! type=number”.
However, in MSIE 8, this apparently doesn’t work :
- the first alert shows “object”,
- the second alert shows an empty string.
- and there is no third alert.
What should I do to make the code work in IE 8 too?
Make it an xml document rather than an HTML fragment with invalid html ( which IE correctly chokes on )