使用jQuery查看div是否具有某个类的子级 [英] Using jQuery to see if a div has a child with a certain class

查看:135
本文介绍了使用jQuery查看div是否具有某个类的子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div #popup ,它使用类 .filled-text 动态填充多个段落。我试图让jQuery告诉我,如果 #popup 中有其中一个段落。

I have a div #popup that is dynamically filled with several paragraphs with the class .filled-text. I'm trying to get jQuery to tell me if #popup has one of these paragraphs in it.

I有这个代码:

$("#text-field").keydown(function(event) {
    if($('#popup').has('p.filled-text')) {
        console.log("Found");
     }
});

有什么建议吗?

推荐答案

您可以使用查找功能:

if($('#popup').find('p.filled-text').length !== 0)
   // Do Stuff

这篇关于使用jQuery查看div是否具有某个类的子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆