473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Collapsible menu for dynamic page

Hello everyone,

So there are a ton of different options on the web for building a collapsible menu (ie click expand to see full list, and collapse to hide the list) however, all of these scripts have one thing in common. They're based off of the lists class or ID.

This is where my problem arises. I have a php page that calls x number of rows from a database and then outputs those rows for the user to view in a table. I want just one field in the table to be collapsible, and just because you expand a field in one row, the fields in the other rows should not be expanded. I'm not sure if you see where my dilemma is but if the solution is class or id based i can't sit here and predefine each row as a separate class or ID mainly because I don't know how many rows there will be at any given time.

Here is the most basic example,
my javascript
Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2.  .row { vertical-align: top; height:auto !important; }
  3.  .list {display:none; }
  4.  .show {display: none; }
  5.  .hide:target + .show {display: inline; }
  6.  .hide:target {display: none; }
  7.  .hide:target ~ .list {display:inline; }
  8.  @media print { .hide, .show { display: none; } }
  9.  </style>
My html:
Expand|Select|Wrap|Line Numbers
  1. <div class="row">
  2.  <a href="#hide1" class="hide" id="hide1">Expand</a>
  3.  <a href="#show1" class="show" id="show1">Collapse</a>
  4.  <div class="list">
  5.  <ul>
  6.  <li>Item 1</li>
  7.  <li>Item 2</li>
  8.  <li>Item 3</li>
  9.  </ul>
  10.  </div>
  11.  </div>
For one instance this works, but if i do multiples only the first expands and collapses.
Jan 24 '14 #1
1 2355
Hi
Try this code
Expand|Select|Wrap|Line Numbers
  1.     <div class="row">
  2.  
  3. <ul>
  4.  
  5.     <li> <a href="#hide1" class="hide">expand </a></li>
  6.         <li> <a href="show" class="show">Collapse </a></li>
  7.  
  8.      <li>Item 1</li>
  9.      <li>Item 2</li>
  10.      <li>Item 3</li>
  11.      </ul>
  12.      </div>
  13.  
  14.  
  15. $('.hide').click(function(){
  16.     var collapse_content_selector = $(this).closest('ul').find('.nav1');                   
  17.     var hide_switch = $(this);
  18.  
  19.     $(collapse_content_selector).toggle(function(){
  20.       if($(this).css('display')=='none'){
  21.         toggle_switch.html('Example <span class="hide"></span>');
  22.       }else{
  23.         toggle_switch.html('Example <span class="show"></span>');
  24.       }
  25.     });
  26.     return false;
  27.   });
  28.  
  29.  
Jan 30 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark | last post by:
I'm interested in displaying a dynamic page title, rather than the static html <title>My Page</title>. In a previous posting, I had seen a suggestion of making the title into a server control...
3
by: vodafone | last post by:
Hy all I've a little problem. I need to write a dynamic page that render control according to validation status return from previous control validation status. To be clear, I've page that...
4
by: Chris | last post by:
Can anyone recommend how to do a screen scrape from a dynamic page and save it to a text file? Regards, Chris.
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
1
by: florencepushpa | last post by:
hi, i need to create a staic and dynamic page in html.pls give the code. Thank u Pushpa
0
by: Marcio Vidal | last post by:
Hello, How can i do one menu follow page down and page up? When i move scroll for down i like menu follor togheter... How i can do this? thanks
5
by: ycquak | last post by:
Hi, Currently I need to read contents from a dynamic page, which goes something like: http://servername/filename.jsp?arg1=a&arg2=b The content is not static, neither is there a file for me to...
1
by: braich | last post by:
Hi All I am new to PHP and have been reading few basic books on PHP. I am trying to create a dynamic page based on the keyword in the url. Let’s say I have...
3
by: user65 | last post by:
Is it possible to have dynamic page titles with an ASP site? Many people would like to share our content on facebook, but can't do so because the page titles are displayed as the URL. I'm not very...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.