Maybe something like this...not tested

var tog = false;

$('a').click(function() {
    $('input[type=checkbox]').each(function() {
        $(this).attr('checked',!tog); // not sure if you need removeAttr for 
checkboxes
    });
    tog=!tog;
});

-- Josh
  ----- Original Message ----- 
  From: Andy Matthews 
  To: [jQuery] 
  Sent: Tuesday, October 30, 2007 9:28 AM
  Subject: [jQuery] Toggle all checkboxes, best way?


  I've got some code which I think is pretty simple. But I'd like to see if 
there's a quicker (less code) way to do this. I simply want to be able to 
toggle all checkboxes on a page on/off.

  Is there a better way?

  var $checkboxes = $('input[type=checkbox]');

  $('a').toggle(function(){
     // toggle me on
     $checkboxes.each(function(){
      $(this).attr('checked','checked');
     });
     return false;
    },function(){
     $checkboxes.each(function(){
      $(this).removeAttr('checked');
     });
    });

  ____________________________________

  Andy Matthews
  Senior ColdFusion Developer

  Office:  877.707.5467 x747
  Direct:  615.627.9747
  Fax:  615.467.6249
  [EMAIL PROTECTED]
  www.dealerskins.com

<<dealerskinslogo.bmp>>

Reply via email to