Jump to content

Using show/hide with multiple results.. one at a time


Go to solution Solved by mac_gyver,

Recommended Posts

I have a script that runs a MySQL query and loops through a bunch of results.

 

For each person's name, I have a short bio that I want to show/hide by clicking on the person's name.  I have a basic start, but I can't figure out how to show/hide them individually. When I click on someone's name, it shows/hides all of the bio's.  I do have an individual ID for each person, and could use that somehow, but I'm scratching my head trying to figure out how to accomplish that.  Any ideas?

 

http://jsfiddle.net/APA2S/3644/

 

  • Solution

you need to use the this selector to reference the current element (to avoid having to manage id's for everything.)

 

there's probably a better way of doing this, but here's one way -

 

<div class="showmenu">Bob Smith
    <div class="menu" style="display: none;">Biography information goes here for bob Smith.</div>
</div>


<div class="showmenu">Jane Doe
    <div class="menu" style="display: none;">Biography information goes here for Jane Doe.</div>
</div>
    $(document).ready(function() {
        $('.showmenu').click(function() {
                $('.menu',this).toggle("slide");
        });
    });

note: id's need to be unique, so i used a class for your showmenu.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.