开发者

How do you find out what element type the root element is with jquery

开发者 https://www.devze.com 2023-01-03 14:08 出处:网络
I\'m sending an ajax request that will either give me an error or a userID <?xml version=\"1.0\" encoding=\"UTF-8\"?>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消