您的位置:首页 > Web前端 > JQuery

Determining whether jQuery has not found any element

2014-09-11 05:54 323 查看
http://stackoverflow.com/questions/2877654/determining-whether-jquery-has-not-found-any-element

$('#idThatDoesnotexist').length
is
what you're looking for. (If it finds nothing, this will
===
0
.) So your conditional statement should probably be:
if($('#id').length) { /* code if found */ } else { /* code if not found */ }


You're getting an object returned from that alert because jQuery (almost) always returns the "jQuery object" when you use it, which is a wrapper for the elements jQuery's found that permits method chaining.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐