How to highlight a column in html table on click using js or jquery?

前端 未结 4 405
日久生厌
日久生厌 2020-12-22 03:10

I am trying to implement a javascript which will highlight the column in an html table on click.As the below working example for row highlight i tried to use the same with t

4条回答
  •  甜味超标
    2020-12-22 03:54

    Please try this:

    $("#dataTable tr td").click(function() {
      //Reset
      $("#dataTable td").removeClass("highlight");
      //Add highlight class to new column
      var index = $(this).index();
      $("#dataTable tr").each(function(i, tr) {
      	$(tr).find('td').eq(index).addClass("highlight");
      });
    });
    .highlight {
      background-color: yellow;
    }
    
    
    Data1Data2
    Data1Data2
    Data1Data2

提交回复
热议问题