Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2008, 04:57 PM   PM User | #1
Crul
New to the CF scene

 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Crul is an unknown quantity at this point
Expand/Collapse using jQuery

I'm implementing an expand/collapse feature but I have a problem:

I have 2 rows in a table...

Code:
<table>
  <tr id="40807386" class="hidden ">testing this</tr>
  <tr id="34893485" class="hidden ">testing this again</tr>
</table>
So I can hide this row by going
Code:
$('.hidden').toggle();
but this hides both the rows when I only want to hide the first row, not both. Is there a way to get the id of the element so that I can go something like
Code:
($(this).id).toggle()
This ^ gives me an error but I need to be able to do something similar. Any help on this would be greatly appreciated

Thanks
Crul is offline   Reply With Quote
Old 11-07-2008, 11:03 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
You could select the elements based on id, see http://docs.jquery.com/Selectors/id#id .But the starting letter of an id value can't be a number. So your markup is invalid now.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 11-07-2008, 08:44 PM   PM User | #3
logictrap
Regular Coder

 
logictrap's Avatar
 
Join Date: Apr 2008
Posts: 155
Thanks: 11
Thanked 3 Times in 3 Posts
logictrap is an unknown quantity at this point
You can also try using these:

.eq(0) - Selects the first item
:first - Selects the first item

There's other ways also. Checkout the documentation on jquery.com for details/examples.
__________________

Which came first - the chicken or the egg? The egg... [ticket closed]
If a tree falls... does it make a sound? Yes.............. [ticket closed]
logictrap is offline   Reply With Quote
Old 11-07-2008, 11:05 PM   PM User | #4
Crul
New to the CF scene

 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Crul is an unknown quantity at this point
but the problem is that I don't know the value of the id, so I need to somehow be able to retrieve the id of the current element $(this)

to do $('#id') I need to know what the id is...


EDIT: nvm guys, I figured it out. Thanks for the help tho, I appreciate it very much

Last edited by Crul; 11-07-2008 at 11:14 PM..
Crul is offline   Reply With Quote
Old 11-08-2008, 12:05 AM   PM User | #5
logictrap
Regular Coder

 
logictrap's Avatar
 
Join Date: Apr 2008
Posts: 155
Thanks: 11
Thanked 3 Times in 3 Posts
logictrap is an unknown quantity at this point
Even without the id this might work:

Code:
$('.hidden').eq(0).toggle();
__________________

Which came first - the chicken or the egg? The egg... [ticket closed]
If a tree falls... does it make a sound? Yes.............. [ticket closed]
logictrap is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:49 AM.


Advertisement
Log in to turn off these ads.