Wednesday, 18 September 2013

Detecting a property checked on a check box and applying a class

Detecting a property checked on a check box and applying a class

I have been using the following code to update div styles when a check box
is checked:
http://jsfiddle.net/tPawr/6/
$(document).ready(function() {
var checkbox = $('input[type="checkbox"]');
var checkimage = $('<div class="checkbox-image" />');
$(checkbox).each(function(){
$(this).show().before(checkimage);
});
$(checkbox).prop('checked',function() {
$('.checkbox-image').addClass('checked');
});
$('checkbox-image').on('click',function(){
$(this).toggleClass('checked').after().prop('checked',$(this).is('.checked'));
});
});
It was working fine, and then it stopped working and I can't work out why?
Can anyone help?

No comments:

Post a Comment