使用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