[jQuery] Check all

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Wolfie
Forum Commoner
Posts: 37
Joined: Wed Jan 28, 2009 8:40 am
Location: Poland

[jQuery] Check all

Post 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 ?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: [jQuery] Check all

Post 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]")...
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply