Bind different events with jQuery eq() and not()

原创
2016/06/17 14:12
阅读数 144

HTML

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 2, cell 3</td>
</tr>
</table>

JS

$(document).ready(function() {

  $("tr").find("td").eq(2).click(function(){
      alert('hi');
  });

  $("tr").find("td").not().eq(2).click(function(){
      alert('hi2');
  });

});

What I'm trying to do here is bind a different click event for the every 3rd <td> of each row and every other <td> different click function. 1st function works but how can I bind event for the <td>'s which are not the 3rd ones?

 

 

Pass the selector to the not method.

$("tr").find("td").not(':eq(2)').click(function(){
     alert('hi2');
});
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部