views:

1397

answers:

1

So I have some html like so:

<div id="avatar_choices">
    <label for="id_choice_0">
     <input id="id_choice_0" type="radio" name="choice" value="7" />
     <img src="someimage.jpg" />
    </label>
    <label for="id_choice_1">
     <input id="id_choice_1" type="radio" name="choice" value="8" />
     <img src="someimage2.jpg" />
    </label>
</div>

And some script:

$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
 $('#avatar_choices img').css('border', '2px solid #efefef');
 $(this).css('border', '2px solid #39c');
 $(this).siblings('input').attr('checked', 'checked');
});

The goal is to allow the user to click around on the image options, having the selected one highlight with a border colour.

This works fine in FF. For some reason in IE once I click on an image, click another image, then try to click the first one, the border won't change (though it does get selected).

EDIT: My solution ended up happening half by accident. I changed the code to this due to redsquare's answer:

$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
    $('#avatar_choices img').removeClass('selected');
    $(this).addClass('selected');
    $(this).siblings('input').attr('checked', 'checked');
});

where:

#avatar_choices img.selected{border:2px solid #39c;}

Go figure.

A: 

best using addClass and removeClass in this scenario. Easier to maintain. Can you paste your full html so I can see your doctype etc

redsquare
So changing things to use addClass and removeClass fixed the problem. Go figure.
defrex