admin管理员组文章数量:1414614
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?
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?
-
Try using
on('click')
instead ofclick
. – Rutwick Gangurde Commented Jan 7, 2013 at 5:06 - click function calls on(click). It's not the issue. Please read the question – Techie Commented Jan 7, 2013 at 5:07
4 Answers
Reset to default 2Pass the selector to the not
method.
$("tr").find("td").not(':eq(2)').click(function(){
alert('hi2');
});
http://jsfiddle/z9HUB/
try this out live fiddle
$(document).ready(function() {
$("tr").find("td:eq(2)").click(function(){
alert('hi2');
});
$("tr").find("td:not(:eq(2))").click(function(){
alert('hi');
});
});
Try $("td:not(:eq(2)")
$("tr").find("td:not(:eq(2)").click(function(){
alert('hi2');
});
You could do something like this:
$(document).ready(function() {
$("tr").find("td:eq(2)").click(function(){
alert('hi');
});
$("tr").find("td:lt(2)").click(function(){
alert('hi2');
});
});
本文标签: javascriptBind different events with jQuery eq() and not()Stack Overflow
版权声明:本文标题:javascript - Bind different events with jQuery eq() and not() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745163560a2645564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论