SF23103 Posted December 20, 2014 Share Posted December 20, 2014 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/ Quote Link to comment https://forums.phpfreaks.com/topic/293190-using-showhide-with-multiple-results-one-at-a-time/ Share on other sites More sharing options...
Solution mac_gyver Posted December 20, 2014 Solution Share Posted December 20, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293190-using-showhide-with-multiple-results-one-at-a-time/#findComment-1500145 Share on other sites More sharing options...
SF23103 Posted December 20, 2014 Author Share Posted December 20, 2014 Worked like a charm, thanks!! And yes, that was my bad with the ID instead of class ;-) Quote Link to comment https://forums.phpfreaks.com/topic/293190-using-showhide-with-multiple-results-one-at-a-time/#findComment-1500183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.