-1

I have a table with tr that have unique numeric ids set. I also have an array that contains the ids.

So basically I need to check if the tr id is in the array of values, if so add or remove a class from an element inside of it.

I have figured this out....

Carl Weis
  • 6,074
  • 14
  • 60
  • 85

3 Answers3

1

with:

var ids = [ /* array of ids */ ];

do:

$('#'+ids.join(',#')).addClass('classy');

Ben
  • 19,879
  • 11
  • 69
  • 113
0

Something like this?

var ARR = [ /* some ids */ ];

$('tr').each(function() {
  if (ARR.indexof($(this).attr('id')) != -1)
     $(this).addClass('hurray!');
});
freakish
  • 51,131
  • 8
  • 123
  • 162
0

Solution assumes same class being add/removed to same elemnt within row. Passing true/false to toggleClass() determines add/remove

$('tr').each(function() {
    var isInArray=$.inArray(parseInt( $(this).attr('id'), 10)) > -1;
    $(this).find(someEleemntSelector).toggleClass('className',isInArray );  
});
charlietfl
  • 169,044
  • 13
  • 113
  • 146