473,659 Members | 3,605 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 5908
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>Dynami c Java Querystring</title>
</head>
<body>
<script type="text/javascript">
<!--
function querySt(param) {
var loc = window.location .search.substri ng(1);
var query = loc.split("&");
for (i=0;i<query.le ngth;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="visibili ty: hidden;">
<p>Div A</p>
</div>
<div id="Db" style="visibili ty: hidden;">
<p>Div B</p>
</div>
<div id="Dc" style="visibili ty: hidden;">
<p>Div C</p>
</div>
<script type="text/javascript">
<!--
document.getEle mentById(queryS t('q')).style.v isibility = '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>Dynami c 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.substri ng(1);
* * * * * * * * var query = loc.split("&");
* * * * * * * * for (i=0;i<query.le ngth;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="visibili ty: hidden;">
<p>Div A</p>
</div>
<div id="Db" style="visibili ty: hidden;">
<p>Div B</p>
</div>
<div id="Dc" style="visibili ty: hidden;">
<p>Div C</p>
</div>
<script type="text/javascript">
<!--
* * * * document.getEle mentById(queryS t('q')).style.v isibility = '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
2502
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 escape key on second form, this should be hidded and should show the first form.... Can some one guide me how to achive this... (MUST USE SHOW & HIDE FORM PROPERTIES). I tried to achive this using the below code but when i check the Windows->Task...
10
4643
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 with the javascript in a toggle fashion. the problem is a know very little javascript and have become incredibly frustrated because i went ahead thinking it was going to be like C. its not. I know i can use these lines to do the actual work:
3
2943
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 it's easy to get something wrong. If the browser does not support the required features, I want it to generate a completely static page with the "details" shown automatically.
4
4219
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
7
29130
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 below the comment with a spell check & submit button. Clicking "Amend" would display the same buttons & text field but pre-populated with the original comment. Using Java Script how do I show / hide the text field in my list of comments but have...
3
7720
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 am finding this sort of problem by far the most annoying part about working with ASP.NET controls. What I want is to know how to do three things: - conditionally show or hide an ImageField +column+ based on whether or not an the...
1
16741
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 div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
1
4164
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. I don`t want to change the way i have used to show and hide layers. check down code :- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
18
4844
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 starting divs on my page, each one expanding onclick. The show/hide elemant works fine. There is one slight problem... I want the user to be able to click anywhere inside the starting div in order for the hidden div to be revealed. This is ok for the...
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.