Search code examples
htmljquerycssradio-button

RemoveClass of other childeren in same parent div


I am trying to replace my radio circles by div's.

The selecting by clicking on the divs works. The highlighting of the selected div works.

But how can i remove the "selected" class of the other childeren in the same parent when i select one of the other options?

My JS is now:

$('.option').click(function() {
    $('input', this).prop("checked", true);
    $(this).addClass('optionSelected');
}

http://jsfiddle.net/S7Js8/


Solution

  • Use siblings() to target the sibling div's,

    $('.option').click(function() {
        $('input', this).prop("checked", true);
        $(this).addClass('optionSelected')
               .siblings()
               .removeClass('optionSelected');
    });​
    

    FIDDLE