Checking a radio box via with the following code;

Checking a radio box via with the following code;

Hi I have the following code;

  1. $('#resultsBox>div>img').each(function(index){
  2.       if($('#'+(index+1)).attr('data-color')==a4){
  3.       $('#'+a4+'_'+index).attr('checked', true).checkboxradio('refresh');
  4.        };
  5. });
The function runs through four images if one has the corresponding data-colour it checks a corresponding radio button.

When I use (index) it only works on the first call but there after doesn't.  

Can anyone help?