admin管理员组文章数量:1323029
Currently I am using
$('#mytable tr').click(function() {
blah blah
});
This makes all rows, including the headers clickable. How can I exclude the headers or <th>
's?
Currently I am using
$('#mytable tr').click(function() {
blah blah
});
This makes all rows, including the headers clickable. How can I exclude the headers or <th>
's?
4 Answers
Reset to default 8Separate you header and body using <thead>
and <tbody>
tags, and change your selector to "#mytable tbody tr"
HTML will look something like this
<table>
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<tr>
...
</tr>
</tbody>
</table>
The easiest way, assuming you've marked your table
up accurately, is to use:
$('#mytable tbody tr').click(function() {
blah blah
});
Failing that:
$('#mytable tr').filter(
function(){
return $(this).find('td').length;
}).click(function() {
$(this).addClass('clicked');
});
JS Fiddle demo.
You can remove them with the not
function:
$('#mytable tr').not('th').click(function() {
blah blah
});
Or:
$('#mytable tr:not(th)').click(function() {
blah blah
});
Use Jquery delegate
$("#mytable").delegate("td", "click", function() {
//Do something
});
this should work
本文标签: javascriptMaking table rows but not table headers clickable in jqueryStack Overflow
版权声明:本文标题:javascript - Making table rows but not table headers clickable in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109653a2421186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论