如何使用jquery检查另一个html元素中的一个html元素excist [英] How check one html element excist inside another html element using jquery

查看:190
本文介绍了如何使用jquery检查另一个html元素中的一个html元素excist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个html元素存在于另一个html元素中,使用jquery.Parent元素有id'preview',而child元素有id'draggable'.How检查子元素是否存在于父元素内?



我的代码是

  if($(#preview)。has(#draggable ).length)
{
alert(First element contains);
}

任何机构都可以为这些问题提供解决方案吗?

$ b $您可以使用 find()函数来查找内部元素< p>选择器>

  if($(#preview)。find(#draggable) .length){
alert(First element contains);
}


I want to check one html element exist inside another html element using jquery.Parent element have id 'preview' and child element have id 'draggable'.How check child element present inside parent element?

My code is

     if($("#preview").has("#draggable").length)
      {
          alert( "First element contain" );
      }

Any body give any solution for these issue?

解决方案

you can use find() function to find inner element <selector>

if($("#preview").find("#draggable").length){
    alert( "First element contain" );
}

这篇关于如何使用jquery检查另一个html元素中的一个html元素excist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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