Viktor Bogutskii
Viktor Bogutskii

Reputation: 930

If checked -> addClass

I have input checkbox

<label for="edit-panes-uc-termsofservice-agreement-checkout-tos-agree-agreed" class="option"><input type="checkbox" class="form-checkbox" value="agreed" id="edit-panes-uc-termsofservice-agreement-checkout-tos-agree-agreed" name="panes[uc_termsofservice_agreement_checkout][tos_agree][agreed]"> I agree with the terms above</label>

and I want to add class to element befcontentleft when it will be checked. Tell me please solution. Thanks.

if($('input#edit-panes-uc-termsofservice-agreement-checkout-tos-agree-agreed').is(':checked') {
     $('befcontentleft').addClass('green');
}

Upvotes: 2

Views: 2697

Answers (2)

John Hartsock
John Hartsock

Reputation: 86872

$('input#edit-panes-uc-termsofservice-agreement-checkout-tos-agree-agreed').change(function () {
  if ($(this).is(":checked")) {
    $('befcontentleft').addClass('green');
  }
});

Upvotes: 2

Naftali
Naftali

Reputation: 146302

$('input#edit-panes-uc-termsofservice-agreement-checkout-tos-agree-agreed').change(function(){
    if(this.checked){
         $('#befcontentleft').addClass('green');
    }
    else {
         //do something else
    }
})

Fiddle: http://jsfiddle.net/maniator/9UQf8/

Upvotes: 5

Related Questions