473,503 Members | 10,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide div

Hello,

In a simple HTML page, index.html, I have:
- 3 anchors: A, B and C;
- 3 divs: dA, dB and dC;

Each anchor should load, when clicked, index.html but anchor A should
make dA visible and the other invisible, anchor B should show dB and
hide the others.

How can I do this?

Thanks,
Miguel
Jun 27 '08 #1
2 5901
On Jun 3, 5:15*pm, shapper <mdmo...@gmail.comwrote:
Hello,

In a simple HTML page, index.html, I have:
- 3 anchors: A, B and C;
- 3 divs: dA, dB and dC;

Each anchor should load, when clicked, index.html but anchor A should
make dA visible and the other invisible, anchor B should show dB and
hide the others.

How can I do this?

Thanks,
Miguel
This was tested very quickly but works in IE 7.

It uses Javascript but you didn't specify a scripting language of
choice.

<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dynamic Java Querystring</title>
</head>
<body>
<script type="text/javascript">
<!--
function querySt(param) {
var loc = window.location.search.substring(1);
var query = loc.split("&");
for (i=0;i<query.length;i++) {
var currParam = query[i].split("=");
if (currParam[0] == param) {
return currParam[1];
}
}
}
-->
</script>
<a href="test.htm?q=Da">A</a>
<a href="test.htm?q=Db">B</a>
<a href="test.htm?q=Dc">C</a>
<div id="Da" style="visibility: hidden;">
<p>Div A</p>
</div>
<div id="Db" style="visibility: hidden;">
<p>Div B</p>
</div>
<div id="Dc" style="visibility: hidden;">
<p>Div C</p>
</div>
<script type="text/javascript">
<!--
document.getElementById(querySt('q')).style.visibi lity = 'visible';
-->
</script>
</body>
</html>
</code>
Jun 27 '08 #2
On Jun 21, 12:55*pm, BRitchie <ritchie.br...@gmail.comwrote:
On Jun 3, 5:15*pm, shapper <mdmo...@gmail.comwrote:
Hello,
In a simple HTML page, index.html, I have:
- 3 anchors: A, B and C;
- 3 divs: dA, dB and dC;
Each anchor should load, when clicked, index.html but anchor A should
make dA visible and the other invisible, anchor B should show dB and
hide the others.
How can I do this?
Thanks,
Miguel

This was tested very quickly but works in IE 7.

It uses Javascript but you didn't specify a scripting language of
choice.

<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dynamic Java Querystring</title>
</head>
<body>
<script type="text/javascript">
<!--
HTML-style comment delimiters should not be used inside script
elements.

* * * * function querySt(param) {
* * * * * * * * var loc = window.location.search.substring(1);
* * * * * * * * var query = loc.split("&");
* * * * * * * * for (i=0;i<query.length;i++) {
* * * * * * * * * * * * var currParam = query[i].split("=");
* * * * * * * * * * * * if (currParam[0] == param) {
* * * * * * * * * * * * return currParam[1];
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }
-->
That is incorrect even if the comment delimiters were useful, it
should be:

//-->

</script>
<a href="test.htm?q=Da">A</a>
<a href="test.htm?q=Db">B</a>
<a href="test.htm?q=Dc">C</a>
<div id="Da" style="visibility: hidden;">
<p>Div A</p>
</div>
<div id="Db" style="visibility: hidden;">
<p>Div B</p>
</div>
<div id="Dc" style="visibility: hidden;">
<p>Div C</p>
</div>
<script type="text/javascript">
<!--
* * * * document.getElementById(querySt('q')).style.visibi lity = 'visible';
-->
The problem with this approach is that if the user has scripting
disabled, or it isn't supported, they will not see any content. Much
better to use the HTML class attribute to associate visibility, then
use script to load the relevant style sheet to set the applicable rule
and hide the elements.
--
Rob
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2475
by: Ajai Kumar .R | last post by:
Hai all, I've two or more forms on my app. My requirement is, Have to show the first form asa the user press a button have to hide the first form and show the second form. If the user press the...
10
4625
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
3
2930
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and...
4
4214
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
7
29120
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
3
7713
by: | last post by:
I'm using the DataList and GridView controls, and I am trying to wrap my head around the problem of conditionally showing or hiding cells/cell content based on the presence or absence of DB data. I...
1
16723
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
1
4150
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. ...
18
4833
by: ryrocks | last post by:
Hi, Im making a 'contact us' page. The user click on the div, this then reveals another larger div displaying more information giving the effect of the box expanding or dropping down. I have 3...
0
7207
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
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7294
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
7361
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...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.