Reputation: 13
$(".TableContainer.MyTable table")
this selector gives me an array of 3 tables. I do highlighting for my tables first 15 table data rows. I want to do this for all tables within the jQuery selector array.
$('#MyTable tbody tr td').slice(0, 15).addClass("highlight");
is what I use to add class highlight
to the first 15 table datas for a single table. How do I use this selector for each table in first selector?
How do I achieve this using .each()
?
Upvotes: 1
Views: 54
Reputation: 171669
You really don't even need each
as there are enough selectors and methods available to do what you need in one chain:
$(".TableContainer.MyTable table").find('tr:lt(16) td').addClass("highlight");
The way this works is the initial collection is the 3 tables and internally jQuery will loop over all 3 (using each
within jQuery core) and perform the methods that follow
Upvotes: 2