473,387 Members | 1,540 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,387 software developers and data experts.

Can I show/hide list items, but have the items start off as hidden?

20
Hello,

I am using javascript to show/hide nested lists. I modified some code originally posted by ACoder on an earlier thread. Currently, however, the page loads with everything showing. My goal is the reverse: the page should load with everything hidden, and only by activating the script will more items be revealed. So, the default would look like this:

Default:

ITEM 1 Click to show more

---

After click:

ITEM 1 Click to show less
Sub Item
Here is my current javascript code:

Expand|Select|Wrap|Line Numbers
  1. function showhideexamples(anchor) {
  2. var span = document.getElementById('subitem1');
  3.     span.style.display = (span.style.display=='block')?'none':'block';
  4.     anchor.innherHTML = (anchor.innherHTML=='Show Examples')?'Hide Examples':'Show Examples';
  5.     }
  6.  
Thanks!
Oct 8 '07 #1
6 3910
TAL651
20
I need to make one clarification. I realize that I could just code [HTML]style="display:none"[/HTML] , but that kind of goes against the idea of semantic xhtml.

Is there a way I can make the nested list start off as hidden, without resorting to entering style markup? Maybe a javascript that activates on page load?

Thanks.
Oct 8 '07 #2
r035198x
13,262 8TB
I need to make one clarification. I realize that I could just code [HTML]style="display:none"[/HTML] , but that kind of goes against the idea of semantic xhtml.

Is there a way I can make the nested list start off as hidden, without resorting to entering style markup? Maybe a javascript that activates on page load?

Thanks.
You've got it then. Just execute a hide script onload of the page.
Oct 8 '07 #3
acoder
16,027 Expert Mod 8TB
You've got it then. Just execute a hide script onload of the page.
Or even use CSS instead, e.g. for an element with id "subitem1":
Expand|Select|Wrap|Line Numbers
  1. #subitem1 { display:none; }
Oct 8 '07 #4
TAL651
20
Or even use CSS instead, e.g. for an element with id "subitem1":
Expand|Select|Wrap|Line Numbers
  1. #subitem1 { display:none; }
Simple and efficient, thanks! Works great.

Now I have one more issue, this one related to the javascript. I'll show the code first, then ask my question:

Javascript code:

Expand|Select|Wrap|Line Numbers
  1. function expandcollapseBGrows(anchor) {
  2.     var span = document.getElementById("BGrows");
  3.     span.style.display = (span.style.display=='block')?'none':'block';
  4.    anchor.innerHTML = (anchor.innerHTML=='hide')?'»':'hide';
  5.    }
  6.  
Now, here's my question. This code currently works - when I click on the hide link, my subitems are hidden and I see a right angle quote. When I click on the right angle quote, my subitems appear, and my link changes to "hide."

If I replace "hide" with "«" in the script, though, I run into a problem. Everything still appears and disappears as it should. However, my link, instead of changing from a right angle quote to a left angle quote, now just changes to a left angle quote, and then stays that way. It doesn't change back to a right angle quote.

This seems strange, since it switches back and forth without problems if it is text. For some reason, though, entity references seem to throw it off.
Oct 9 '07 #5
TAL651
20
Simple and efficient, thanks! Works great.

Now I have one more issue, this one related to the javascript. I'll show the code first, then ask my question:

Javascript code:

Expand|Select|Wrap|Line Numbers
  1. function expandcollapseBGrows(anchor) {
  2.     var span = document.getElementById("BGrows");
  3.     span.style.display = (span.style.display=='block')?'none':'block';
  4.    anchor.innerHTML = (anchor.innerHTML=='hide')?'»':'hide';
  5.    }
  6.  
Now, here's my question. This code currently works - when I click on the hide link, my subitems are hidden and I see a right angle quote. When I click on the right angle quote, my subitems appear, and my link changes to "hide."

If I replace "hide" with "«" in the script, though, I run into a problem. Everything still appears and disappears as it should. However, my link, instead of changing from a right angle quote to a left angle quote, now just changes to a left angle quote, and then stays that way. It doesn't change back to a right angle quote.

This seems strange, since it switches back and forth without problems if it is text. For some reason, though, entity references seem to throw it off.
I'm going to move this to a new post, since it's a different question than the original post...
Oct 9 '07 #6
acoder
16,027 Expert Mod 8TB
Simple and efficient, thanks! Works great.
JavaScript is great, but not always the best tool for every problem.
Oct 9 '07 #7

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

Similar topics

2
by: steven | last post by:
Hi, sorry for the crosspost, but I'm not sure if my problem is with the HTML or the CSS :-( URL: http://www.nenya.be/temp/list.htm I have a list with in each list item a text + link which are...
13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
2
by: Greg | last post by:
Hello, I am trying to display order ids and order details (order items). I would like to give the user Hide/Show option to either display or hide order details. The page would look like: ...
1
by: Richard | last post by:
Hello there, I have a form that is called from a Sub Main procedure using application.run(Form1). On my main form there is a button to open an instance of Form2 and then at the same time hide...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
1
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
1
by: nithingujjar | last post by:
Hi, I need to to hide a field"addr_state1" based on a value in the drop down list field called "addr_country".i.e.,if addr_country.value=="in" then hide addr_state1 else , and if the value in the...
3
by: timplx | last post by:
Hello all, New to javascript and have never worked with programming languages like c++, so my logic in some of these statements might be incorrect or redundant Got a problem with my page......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.