jQuery get all node names (both parent and children)
I have an XML document that gets generated by an object. I have no idea what it will really look like at the time of the jQuery AJAX call. What I would like to do is parse through the XML by 开发者_开发百科parent and child getting the node names.
Any direction you can offer will be of great service.
Thanks!
You should be able to parse through XML the same way you parse through DOM elements in jquery;
http://jsfiddle.net/TBwm8/3/
var xml = "<root><stuff></stuff><stuff><stuffchild></stuffchild></stuff></root>";
function alertit(jqueryObject) {
if (jqueryObject.length === 0) return;
jqueryObject.each(function() {
alert(this.nodeName.toLowerCase());
});
alertit(jqueryObject.children());
}
alertit($(xml));
Have you looked at jParse?
精彩评论