On Jun 30, 12:24 pm, "evanbu...@gmail.com" <evanbu...@gmail.com>
wrote:
>                 $(':checkbox.chkEvent').each(function() {
>                     var el = $(this);
>                     el.attr('checked', el.is(':checked') ? '' :
> 'checked');
>                   })

Avoid attr(), and try to avoid fitting every problem into a jQuery
solution...

Try this simple code:

$(':checkbox.chkEvent').each(function() {
  this.checked = !this.checked;
}

I also keep my "run" plugin handy for simple things like this:

// A General "run" function to simplify coding
$.fn.run = function(fn) {
        if (typeof fn=='string') { fn = new Function(fn); }
        this.each(fn);
}

Then:

$(':checkbox.chkEvent').run("this.checked = !this.checked");

Whether that's actually more efficient to write depends on the
situation ;)

Matt Kruse

Reply via email to