使用Jquery将鼠标悬停在元素的前24个子节点上

use*_*906 2 javascript jquery jquery-selectors

我想在前24个孩子上添加一个悬停,在另一个元素的24个单独元素上添加填充.

像这样:

$('tr td:nth-child(1)').mouseover(function(){
  $('rect:nth-of-type(1)').css("fill", "black" );
});

$('tr td:nth-child(2)').mouseover(function(){  
  $('rect:nth-of-type(2)').css("fill", "black" );
});

$('tr td:nth-child(3)').mouseover(function(){
  $('rect:nth-of-type(3)').css("fill", "black" );
});
Run Code Online (Sandbox Code Playgroud)

但我不想重复自己24次.什么是处理这个的最好方法?