Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    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]

  • #4
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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-08-2008 at 12:14 AM.

  • #5
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    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]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •