Page 1 of 1

[jQuery] Check all

Posted: Mon Nov 02, 2009 6:32 am
by Wolfie
Hi guys,


I have this html code :

Code: Select all

 {include file="header.tpl"}<form action="index.php" method="post">{include file="menu.tpl"}    <div id="messages">        <div class="container">            <div id="msgs_labels">                <div style="width: 50px;"><input type="checkbox" id="checkall"></div>                <div style="width: 250px">From:</div>                <div style="width: 550px">Title:</div>                <div style="width: 150px">Date:</div>            </div>        </div>        <div class="container">                        {section name="i" loop=$parts}                <div style="width:50px;clear:both">                    <input class="check" type="checkbox" name="msgs_id[]" value="{$parts[i].id}">                </div>            <div class="click">                <div style="width: 250px">{$parts[i].from}</div>                <div style="width: 550px">{$parts[i].subjects}</div>                <div style="width: 150px">{$parts[i].date}</div>                <div><input type="hidden" name="{$box_name}" value="{$parts[i].id}" class="{$controller}"></div>            </div>            {/section}            <div id="learn">            <input type="hidden" name="controller" value="{$controller}" />            <input type="hidden" name="action" value="mailbox" />            <input type="submit" name="message" value="Spam" />            <input type="submit" name="message" value="Ham" />            </div>                    </div>    </div></form>{include file="footer.tpl"} 
And now I am trying to check all checkboxes in second div with class="container" by clicking on checkbox in first div with class="conteiner"

I made a code in jQuery but it doesn't work :

Code: Select all

 $('#checkall').click(function () {        $('#messages').parents('#container:eq(1)').find(':checkbox').attr('checked', this.checked);    }); 

Anybody can tell me what I am doing wrong ?

Re: [jQuery] Check all

Posted: Mon Nov 02, 2009 9:55 am
by pickle
"container" is a class, not an ID.

I think your selector can be trimmed down too:

Code: Select all

$("#messages .container input[type=checkbox]")...