找到相同jquery的元素

时间:2013-12-11 07:27:15

标签: jquery

我有th个元素的集合,在th元素的点击处理程序中,我想在列表中找到与点击处理程序中的e.target相同的项目

var $ths = $('table th');

$ths.on('click', function(e){
   var $th = $(e.target);
   //how to get the index of $th in $trs
});

我想知道我点击了哪个th(第一,第二,第三等)。

(我无法控制标记,因为这是在页面上加载的第三方库。)

1 个答案:

答案 0 :(得分:2)

index()返回元素索引。

尝试:

$ths.on('click', function(e){
   var $th = $(this).index();
   alert($th);
});
相关问题