Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

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 06-17-2010, 02:45 AM   PM User | #1
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
hide all elements except current value in case statement using jquery

Hey all,

So I thought I was making significant progress refactoring some javascript tabs I initially created in pure javascript, but now resorted to jQuery. While I can get it to correctly display the right div container using $(displayDiv).show(); in the below code. The problem is I try to use the .empty() method to empty the outer content container so I can then display ONLY the specific div. However empty() empties the outer container and then fails to show the specific div I specify:


Code:
$(document).ready(function()
{
	
	var linksToInt = { 
		"#pple": 0,
		"#serv": 1,
		"#sol": 2
	}
	
	/*
	links = document.getElementsByTagName("a");
	if(links.className.indexOf("div-link") > -1){
		links.onclick = function{ removeHash(this.getAttribute("href"));};
	}
	*/
	
	
	$("a.div-link").click(function(){displayDiv($(this).attr("href"));});
	
	function displayDiv(id){
	var linkInt = linksToInt[id];
	on_btn_click(linkInt);
	}
	
	function on_btn_click(displayDiv){
		displayDiv != null ? null : this;
		
		switch(displayDiv){
			case 0:
				$("#content").empty();
				$(displayDiv).show();
				break;
			case 1:
				$("#content").empty();
				$(displayDiv).show();
				break;
			case 2:	
				$("#content").empty();
				$(displayDiv).show();
				break;
			case 3:
				$("#content").empty();
				$(displayDiv).show();
				break;
		}
	}

});
Code:
<div id="content">
	<div class="tabContent" id="pple">
		<p>
			Some Content.
		</p>	
	</div>

	<div class="tabContent" id="serv">
		<p>
			Some Content
		</p>	

	</div>

	<div class="tabContent" id="sol">	
		<p>
			Some Content
		</p>	
	</div>			
</div>
Any suggestions? thanks.
johnmerlino is offline   Reply With Quote
Old 06-18-2010, 12:19 AM   PM User | #2
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
Anyone know why this is telling me there is a syntax error:
Code:
		switch(displayDiv){
			case 0:
				function(){$("#content > div").hide(); $(displayDiv).show();};	
				break;
			case 1:
				function(){$("#content > div").hide(); $(displayDiv).show();};	
				break;
			case 2:	
				function(){$("#content > div").hide(); $(displayDiv).show();};	
				break;
			case 3:
				function(){$("#content > div").hide(); $(displayDiv).show();};	
				break;
		}
johnmerlino is offline   Reply With Quote
Old 06-18-2010, 11:22 AM   PM User | #3
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,881
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
what’s the error message?
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 06-18-2010, 12:23 PM   PM User | #4
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
This is all that firebug tells me:

syntax error
[Break on this error] function(){$("#content > div").hide(); $(displayDiv).show();}; \n
johnmerlino is offline   Reply With Quote
Reply

Bookmarks

Tags
hide, javascript, jquery, show, tabs

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 02:31 PM.


Advertisement
Log in to turn off these ads.