jQuery checkbox goodness
I was working on a select all feature today and just wanted to share this with the world. (a.k.a. keep it for later)
$(document).ready( function() { $('a#select_all').click( function() { $('input:checkbox').each( function() { this.checked = !this.checked; }); return false; }); });
The first item to note is that jQuery created pseudo classes for input.
$('input:checkbox'); ... $('input:textbox'); ... etc.
The second item to note, which I thought was ingenious, was setting the value of the checkbox to the inverse of it’s current value.
this.checked = !this.checked;
Works great and it’s short and sweet. Who loves jQuery?
Related Posts
A Year of Gratitude
It’s funny how perspective changes everything. As I sit here reflecting during Thanksgiving week, I’m struck by just how different things feel compared to a year ago. Sometimes you don’t...
Jenney Journal, part 32
Things have been going really well as Jenney heals at home. She’s back to doing everything she was always able to do, and our latest scans have shown no signs...
Jenney Journal, part 31
On Oct 21, Jenney started to get nauseous and diarrhea. She became very dehydrated quickly, and had a seizure. I called our oncologist who said we should call 911 and...