Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2011, 11:04 AM   PM User | #1
kenshn111
New Coder

 
Join Date: May 2010
Posts: 75
Thanks: 13
Thanked 2 Times in 2 Posts
kenshn111 is an unknown quantity at this point
Hide/Show the following DIV if clicked?

I know that this can be done using .hide/.show... I don't know how to say this but if you'll look at the code:
Code:
<div id="isclickable">
klasdlkasdklaklsjd
<div id="weeeee">
trolololololol
</div>
</div>
<div id="isclickable">
klasdlkasdklaklsjd
<div id="weeeee">
trolololololol
</div>
</div>
The div having an id of "weeeee" will show if id="isclickable" is clicked.. but not all divs having "weeeee" should show but instead what is inside the div "isclickable" is there a way to attain this without creating multiple scripts and ids?

Thanks>
kenshn111 is offline   Reply With Quote
Old 12-28-2011, 11:29 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
something like the following:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
	<title>TITLE</title>
</head>
<body>

<div id="containerDiv">
	<div id="isclickable1" class="isclickable">
		klasdlkasdklaklsjd
		<div id="weeeee1" class="weeeee" style="display:none">
			trolololololol
		</div>
	</div>

	<div id="isclickable2" class="isclickable">
		klasdlkasdklaklsjd
		<div id="weeeee2" class="weeeee" style="display:none">
			trolololololol
		</div>
	</div>
</div>

<script type="text/javascript">
	function attachToggleDivHandler(divObj)
	{
		divObj.onclick = function()
		{
			var isclickableDivs = this.getElementsByTagName('div');
			for (var j=0; j<isclickableDivs.length; j++)
			{
				if (isclickableDivs[j].className == "weeeee")
				{
					isclickableDivs[j].style.display = (isclickableDivs[j].style.display == "block") ? "none" : "block";
				}
			}
		};
	}

	window.onload = function()
	{
		var containerDivDivs = document.getElementById('containerDiv').getElementsByTagName('div');
		for (var i=0; i<containerDivDivs.length; i++)
		{
			if (containerDivDivs[i].className == "isclickable")
			{
				attachToggleDivHandler(containerDivDivs[i]);
			}
		}
	};
</script>

</body>
</html>
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Users who have thanked chump2877 for this post:
kenshn111 (12-28-2011)
Old 12-28-2011, 01:10 PM   PM User | #3
kenshn111
New Coder

 
Join Date: May 2010
Posts: 75
Thanks: 13
Thanked 2 Times in 2 Posts
kenshn111 is an unknown quantity at this point
Thank you very much!!
kenshn111 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:58 AM.


Advertisement
Log in to turn off these ads.