teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コードの内容を変更

2017/03/30 05:04

投稿

taqm
taqm

スコア65

answer CHANGED
@@ -10,16 +10,9 @@
10
10
 
11
11
  ```JavaScript
12
12
  $(function() {
13
- // あらかじめ何列目なのかの情報を付与しておく
14
- $('.matrix tr').each(function() {
15
- $('> *' this).each(function(e, idx) {
16
- $(this).data('idx', idx);
17
- });
18
- });
19
-
20
- // マウスイベントの追加
21
13
  $('.matrix').find('th, td').on('mouseenter', function() {
14
+ // マウスカーソルがのっているセルが左から何番目かを取得
22
- var idx = $(this).data('idx');
15
+ var idx = $(this).parent().find('th, td').index(this);
23
16
  if (idx <= 0) return;
24
17
  var s = '.matrix tr > *:nth-of-type(' +(idx+1)+ ')';
25
18
  $(s).addClass('cursor');