-1

I have some a table in which i have rows with same id and other rows with other same id. Every row has a checkbox and i want to change the backgroundcolor of all the unchecked checkbox inside all rows with one id. this is what i try to do:

function resetOtherCheckBox(){
   $('#sent').find('input:checkbox:not(:checked)').css('background-color', '#33CCCC');
}

what is the error? help me pls

Jayyrus
  • 12,961
  • 41
  • 132
  • 214
  • possible duplicate of [How to get values of that are checked?](http://stackoverflow.com/questions/1806882/how-to-get-values-of-input-type-checkbox-that-are-checked) – Jakub Feb 14 '12 at 21:10
  • i would assume that `resetOtherCheckBox` is never called. – zzzzBov Feb 14 '12 at 21:10
  • 1
    You just cannot have multiple times the same ID - this will lead to unexpected results. Change this to use a class or a data- attribute. – Didier Ghys Feb 14 '12 at 21:11
  • i call it in another function :var checked = $("input[type=checkbox]:checked"); var nbChecked = checked.size(); if(nbChecked==1){ $('tr[name="' + checked.attr('name') + '"]').css('background-color', '#ffff33'); resetOtherCheckBox();.......... – Jayyrus Feb 14 '12 at 21:11
  • alternatively, `#sent` might not be a parent of the checkboxes. You'll have to post more code if you want more help beyond speculation. – zzzzBov Feb 14 '12 at 21:12
  • @DidierGhys no way :( it doesn't work with class.. i change in $("tr.sent").... – Jayyrus Feb 14 '12 at 21:12

3 Answers3

2

I solve in this way:

$("tr.sent input[type=checkbox]:not(:checked)").parents('tr').css('background-color', '#33CCCC');
Jayyrus
  • 12,961
  • 41
  • 132
  • 214
1
$('#sent').find('input[type=checkbox]').not(':checked')
Headshota
  • 21,021
  • 11
  • 61
  • 82
0

Have a look at this fiddle: http://jsfiddle.net/3KWSr/1/

T. Junghans
  • 11,385
  • 7
  • 52
  • 75