【问题标题】:jQuery: Selecting an element in inside an already selected elementjQuery:在已选择的元素内选择一个元素
【发布时间】:2009-03-10 11:21:15
【问题描述】:

例如:

$("table tr").click( function(event)
{
   //Say, here i want get the data of td element where its class name="special"
});

有什么方法可以在点击事件中选择一个元素,在$("table tr")上方的附加元素下的一个元素?

【问题讨论】:

    标签: javascript jquery dom


    【解决方案1】:

    在这种特定情况下,您可以这样做:

    $("table tr").click( function(event)
    {
       $(this).children('td.special').whatEverYouNeed();
    });
    

    一般来说,你需要使用find()

    $("table tr").click( function(event)
    {
       $(this).find('td.special').whatEverYouNeed();
    });
    

    【讨论】:

    • 您也可以使用$('td.special', this) - 这会将选择器的范围限制为容器this
    【解决方案2】:

    类似

    $(this).find(".special").html();
    

    我认为这行得通

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      • 2020-04-27
      • 2010-12-16
      • 1970-01-01
      相关资源
      最近更新 更多