【问题标题】:jQuery hide div that contains certain textjQuery隐藏包含某些文本的div
【发布时间】:2022-01-20 22:01:27
【问题描述】:

在我的网站上,我有 3 类员工

  • 咖啡师
  • 咖啡师01
  • 安全 我想隐藏 barista01 选项,但保留其他选项(请参考图片)。

当我尝试使用$("div:contains('barista01')").parent('div').hide(); 时,我得到一个全黑窗口,里面隐藏着所有东西。 有没有办法解决这个问题?

提前谢谢你 enter image description here

【问题讨论】:

  • 你能分享一些你在截图中给出的 HTML 吗?
  • <div class="hc-mt3" style="background-size: cover;"> <div class="hc-border hc-rounded hc-p2" style="border-color: gray; background-size: cover;"> <div style="background-size: cover;"> <div style="background-size: cover;"> <div class="hc-inline-block hc-valign-middle hc-mr2" style="background-size: cover;"> <div class="hc-inline-block hc-px1 hc-rounded" style="background-color: rgb(203, 232, 107); background-size: cover;"> </div> </div> <div class="hc-inline-block hc-valign-middle" style="background-size: cover;">barista01</div>
  • 空间有限,无法输入更多代码...
  • 如果 Class("hc-mt3) 是固定的,那么你可以使用: $("div:contains('barista01')").parent('.hc-mt3').hide() ;
  • 谢谢。有效。我怎样才能唱出正确的答案?

标签: html jquery wordpress


【解决方案1】:

如果类名“.hc-mt3”是固定的并且不会更改,那么您可以定位该类。 见示例代码:$("div:contains('barista01')").parent('.hc-mt3').hide();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多