P
P
Pavel2020-05-04 10:48:44
JavaScript
Pavel, 2020-05-04 10:48:44

How to highlight columns in a table depending on thead?

example on jsfiddle https://jsfiddle.net/KLON/z0dxus7w/1/
if thdead last name has a class, how to highlight names? html markup can only be changed for thead , tbody must be css or jquery

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-04
@mrusklon

const $table = $('table');
const indices = $table.find('thead .red').get().map((n, i) => $(n).index());

$table
  .find('tbody tr')
  .each((_, n) => $('td', n).filter(i => indices.includes(i)).addClass('red'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question