开发者

Add mouse event to colgroup or col

Is it possible to add jQuery 开发者_开发技巧mouse events on cols or colgroups. We have tried to do so, but it didn't seem to work. On the other hand those cols have a real width and height. Is there a way to make those event work with col?


I'm not sure that a colgroup can be given handlers that would react to events over any cell in the group.

You could alternatively give each cell in the group a specific class. Although, if there are a "lot", it wouldn't perform well.

<tr>
  <td class="c1"> column1 </td>
  <td></td>
</tr>

...

cols1 = $(".c1").css('background','#EEE');

Once you get a handle on cols1, keep it until the DOM structure of the table cells change. You won't have to keep iterating the DOM via the selector to get the collection of DOM elements which match.


You might be able to achieve what you're after using the nth-child selector: http://api.jquery.com/nth-child-selector/

$('tr > td:nth-child(1)').length; // col 1
$('tr > td:nth-child(2)').length; // col 2
$('tr > td:nth-child(3)').length; // col 3
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜