How do you find out what element type the root element is with jquery
I'm sending an ajax request that will either give me an error or a userID
<?xml version="1.0" encoding="UTF-8"?>
<error>1000</error>
<?xml version="1.0" encoding="UTF-8"?>
<userID>8</userID>
how can I find out if the root element is error or userID using jquery or just javascript in general. Using the fi开发者_如何学运维nd method doesn't appear to work if what you're trying to access is the root element
Just use is
:
var xml = $('<?xml version="1.0" encoding="UTF-8"?><userID>8</userID>');
if (xml.is('userID')){
// true
} else {
// false
}
You can call filter
or is
instead of find
.
Unlike find
, which searches the descendants of the elements in the jQuery object (but not the elements themselves), these methods search only the actual elements in the jQuery object.
精彩评论