-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,794
  • 15
  • 63
  • 86

3 Answers3

1

with:

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

do:

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

Ben
  • 20,737
  • 12
  • 71
  • 115
0

Something like this?

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

$('tr').each(function() {
  if (ARR.indexof($(this).attr('id')) != -1)
     $(this).addClass('hurray!');
});
freakish
  • 54,167
  • 9
  • 132
  • 169
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
  • 170,828
  • 13
  • 121
  • 150