The quick and dirty way is to just use a checkbox as the triggering
element - that way you can mimic its state. I think the below would work:
$("#triggercheck").click(function() {
var trigger = this;
$("#chkList input:checkbox").attr("checked", trigger.checked );
});
Using a button as the trigger would entail a bit more code, because you'd
want to use the toggle method, or manage the toggle state some other way.
-- Josh
----- Original Message -----
From: "AzamSharp" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Saturday, May 10, 2008 11:01 AM
Subject: [jQuery] Re: Selecting Checkboxes inside the table
That is very good way!
What would be the best way to do check and uncheck based on the button
click?
On May 10, 12:48 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
Try this out:
$("#chkList input:checkbox").attr("checked",true);
This says: "get all input fields of type checkbox, within table id
'chkList', and set attribute checked of those inputs to true."
You don't need to use the method "each" because jQuery will automatically
iterate over the returned elements.
-- Josh
----- Original Message -----
From: "AzamSharp" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Saturday, May 10, 2008 9:54 AM
Subject: [jQuery] Selecting Checkboxes inside the table
> I am having trouble to check the checkboxes contained inside the HTML
> table.
> Here is the table code:
> <table id="chkList" border="0">
> <tr>
> <td><input id="chkList_0" type="checkbox" name="chkList$0" /><label
> for="chkList_0">Item 1</label></td>
> </tr><tr>
> <td><input id="chkList_1" type="checkbox" name="chkList$1" /><label
> for="chkList_1">Item 2</label></td>
> </tr><tr>
> <td><input id="chkList_2" type="checkbox" name="chkList$2" /><label
> for="chkList_2">Item 3</label></td>
> </tr>
> </table>
> I am using the following code to check all the checkboxes but it does
> NOTHING!
> ($("#chkList").children({"input":"checkbox"}).each(function()
> {
> this.checked = true;
> }));