1

need to add a class to the container that has no input selected this is my attempt jquery:

$('.section .container-items input:checked').each( function(){
     $('.section .container-items').addClass('red');
});

I need this result enter image description here

JSFIDDLE

2
  • I don't understand what the question is. Commented May 9, 2014 at 17:09
  • Need to add a class to the container that has no input selected Commented May 9, 2014 at 17:11

3 Answers 3

1

Use this:

$("input[type=radio]").on('click', function() {
    var container = $(this).parent().parent();
    $(".container-items", container).each(function() {
        $(this).addClass("red");
    });
    $(this).parent().removeClass("red");
});

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use .change().

$('.section .container-items input').change( function(){
    $(this).parent().removeClass('red').siblings().addClass('red');
});

Example Here

Comments

0

Fiddle Demo

var chck = $('.section .container-items input');//cache selector
chck.change(function () { //change event
    chck.filter(':not(:checked)').parent().addClass('red'); //add red to class red to parent if not checked
    chck.filter(':checked').parent().removeClass('red'); //checked elements remove red class
}).change(); //trigger change event

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.