【问题标题】:using jquery, accessing parent div and checking if it has a specific class使用 jquery,访问父 div 并检查它是否有特定的类
【发布时间】:2019-05-25 11:41:19
【问题描述】:

我如何访问父 div 并检查它是否有特定的类

<div class="current">
    <img src="aaa.jpg" class="me-child">
</div>

使用 jquery 点击div 并使用this 关键字,我想知道父div 是否有current 的类

谢谢

【问题讨论】:

  • 您的 HTML 错误。 :(
  • if($(this).closest('div').hasClass('current'))if($(this).parent().hasClass('current'))
  • 然后给你^...
  • @KiranJoshi 谁会使用搜索词祖先?我永远不会发现 (-:

标签: jquery html


【解决方案1】:
if($(this).parent().hasClass("current")) return true;

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    相关资源
    最近更新 更多