Solved

simple show hide this div depending on id

Posted on 2012-04-01
4
431 Views
Last Modified: 2012-08-14
i have 10 div's.

i am looking for a simple javascript that allows me to do the following.

i have a menu bar that says;
div 1
div 2
div 3
etc.

when i click div1, i want it to show div 1, and hide all the rest because they do not have
the div id# div1

the catch is, i want it linked to the div's class or id name
basicly like a onclick=get.this type code

so example, when clicking on the div 1 link,
the div 1 link will show the div with that related link# and id# div1

hopefully that explains it all.

thanks
0
Comment
Question by:webdott
4 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 300 total points
ID: 37794568
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37794850
var state=true;

$('document').ready(function() {
	$('div').click(function () {
		if(state == true) {
			$('div').hide();
			$(this).show();
			
			state = false;
		} 
		else {
			$('div').show();
			state = true;
		}
	})
})

Open in new window

0
 
LVL 16

Assisted Solution

by:HagayMandel
HagayMandel earned 200 total points
ID: 37795455
Your question is  not clear.
How can you hide divs and then click on them?
If you only want to get the div's data abs characteristics, check this sample: http://jsfiddle.net/EKZu3/
0
 

Author Closing Comment

by:webdott
ID: 37796112
Thank you both.

That is exactly what I am looking for.

HagayMandel - yours uses jquery which is nice to have that option.
I have to check to see if all mobile devices can use jquery. I believe
they can, I just have not checked into it yet.

Thanks again for the quick and exact answers!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now