tags:

views:

38

answers:

1

I want to clear the selection of checkboxes if they click cancel. How can I achive this with this code:

var chkbox= $('#divListBox').find(':checked')
                 .map(function() {
                     return $(this).val();
                 }).get();
+2  A: 

This should work:

$('#divListBox').find(':checked').each(function() {
   $(this).removeAttr('checked');
});
Andreas Bonini
`$(this).removeAttr('checked');` is prettier, methinks. +1
karim79
As far as I know jQuery can apply a function on a collection of elements, so the following will work as well: $('#divListBox').find(':checked').attr('checked', '');
mhitza
@ Andreas Bonini and karim79 -- thanks guys, both works!
hersh
If you want pretty, I'd remove the `.find()` and the `.each()` and do something more like this: `$('#divListBox :checked').removeAttr('checked');` :o)
patrick dw