【问题标题】:jquery select element inside a classjquery选择类中的元素
【发布时间】:2010-04-20 04:28:03
【问题描述】:

我想在这样的 div 中选择一个锚点

<div class="response content">
  Disapproved Bank Mandiri<br><br>
  <p>
    <a class="showlist" href="#">Back to list?</a>
  </p>
</div>

执行此操作的 jquery 是什么?

【问题讨论】:

标签: jquery jquery-selectors


【解决方案1】:

div 中任何带有“response”和“content”类的锚点:

$('.response.content a')

或者只有“showlist”类的主播:

$('.response.content a.showlist')

【讨论】:

    【解决方案2】:

    如果您在DIV 上需要这两个课程:

    $("div.response.content a.showlist");
    

    如果没有,

    $("div.response a.showlist");
    

    要了解更多关于 jQuery 选择器的基本用法,请访问http://api.jquery.com/category/selectors/

    【讨论】:

      【解决方案3】:

      解决此问题的另一种方法是使用 jQuery .find()

      这是一个使用 find() 选择 div 中具有“响应内容”类的所有元素的示例。

      jQuery('.response.content').find('a');
      

      这也是一篇访问selectors vs. .find()主题的有用帖子

      【讨论】:

        【解决方案4】:

        你可以使用:

        $('.response').find('a');
        

        或者

        $('.response').find('.showlist');
        

        【讨论】:

          猜你喜欢
          • 2011-01-14
          • 1970-01-01
          • 2012-07-26
          • 1970-01-01
          • 1970-01-01
          • 2011-09-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多