jquery怎么判断body的子元素是否存在?

<html>
<head></head>
<body>

<div class="buy-popup"></div>

</body>
</html>

怎么判断body的子元素 class="buy-popup",是否存在?

这个子元素指的是直接孩子,如果他在body孙子节点上,不算。

大侠指点指点,玩了好久js,还是这么菜,嘿嘿!

阅读 3.8k
1 个回答

CSS 选择器 写法:

$('body>.buy-popup').length > 0

.children() 方法:

$('body').children('.buy-popup').length > 0

面向谷歌编程方法:

搜索:jquery children only

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题