$('input').change(function() { $('div').removeClass('open close').addClass( this.checked && this.value == 1? 'open' : 'close'); });