【问题标题】:jQuery: Check for next element, if not hidejQuery:检查下一个元素,如果不隐藏
【发布时间】:2011-04-04 00:34:07
【问题描述】:

我有一些 H3 元素,有时后面跟着一个 P 元素。我想检查一下h3之后的下一个元素是否是p,如果不是,隐藏那个h3。

【问题讨论】:

    标签: jquery next


    【解决方案1】:
    $('h3').filter(function() { return !$(this).next().is('p') }).hide();
    

    【讨论】:

      【解决方案2】:
      $('h3').each(function(n, e) {
          $(e).next().is('p') || $(e).hide();
      });
      

      【讨论】:

        猜你喜欢
        • 2010-09-15
        • 2016-08-09
        • 2015-03-01
        • 1970-01-01
        相关资源
        最近更新 更多