<script type='text/javascript'> $(document).ready(function() { $('#pHeader').click(function() { $('#pBody').slideToggle('fast'); }); }); </script> <asp:Panel ID='pHeader' runat='server' CssClass='cpHeader'> <asp:Label ID='lblText' runat='server' Text='Header' /> </asp:Panel> <asp:Panel ID='pBody' runat='server' CssClass='cpBody'> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur </asp:Panel>
As you can see from the above I am trying to achieve a collapsible panel. However the above will only work once. How can I make this accessible to multiple controls, i.e. if I have 10 panels on a page?
Thanks guys!
Try this:
If you select by ID (e.g.,
#pHeader), you’ll only affect one node, since IDs are meant to be unique. Classes are meant to be assigned to multiple nodes.Also note the shortened first line, which jQuery provides as a shortcut for
$(document).ready().