?
Solved

how do you make a tab "active" based on a url parameter but then be able to "deactive" when you click another div

Posted on 2014-07-31
2
Medium Priority
?
114 Views
Last Modified: 2014-08-01
Hi,

I have some code  that will activate a div if the user goes to the index page. The problem is that the div will stay active if the user clicks on another link. The corresponding div should be active with the link.

Here is the code

Thanks!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Tabs - Default functionality</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() { 
    $("div a").click(function() {
        var v = $(this).attr("id");
        $("#recipientId").val(v);
    });
});
</script> 
<style>
.blue_container {
	   background-color:#417DBE;
    margin: 0px 0px 0px 0px;
    padding: 10px 15px 0px 5px;
	width:180px;
	height:95px;
	margin-top:-20px;
	    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    text-align:left;
}
.ForMembers a {
	font-size:12px;
	font-family:Georgia, "Times New Roman", Times, serif;
}
#MemCovInfo {
width:685px;
}
#ForMembers {
   background-color:#417DBE;
    margin: 0px 0px 0px 0px;
    padding: 10px 15px 0px 5px;
	width:180px;
	height:95px;
	margin-top:-20px;
	    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    text-align:left;
	} 
	
	#ForMembers a {
	color:#FFF;
	 font-family:Georgia, "Times New Roman", Times, serif;
    font-size: 20px;
    cursor:pointer;
	}
#ForMembers a:hover {
color:#000;
}

#ForMembers:hover {
background-color:#CCC;
 color:#000;
 cursor:pointer;
}

	#Coverage {
   background-color:#417DBE;
    margin: 0px 0px 0px 0px;
    padding: 10px 15px 0px 5px;
    width:200px;
	height:95px;	
	margin-left:205px;
	margin-top:-105px;
	   -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    text-align:left;	
	}
	#Coverage:hover {
background-color:#CCC;
 cursor:pointer;
}
	#Coverage a  {	
	 font-family:Georgia, "Times New Roman", Times, serif;
   font-size:20px;
   color:#FFF;
	}
	#Coverage a:hover  {
   color:#000;
	}	
	#GenInfo {
   background-color:#417DBE;
    margin: 0px 0px 0px 0px;
    padding: 10px 15px 0px 5px;
	width:190px;
	height:95px;
	font-size:14px;
	margin-left:430px;
	margin-top:-105px;
	   -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    text-align:left;	
	}
	
	#GenInfo:hover {
	background-color:#CCC;
 cursor:pointer;
 }	
#GenInfo a  {
	color:#FFF;
	 font-family:Georgia, "Times New Roman", Times, serif;
  font-size:20px;
	}
	
	#GenInfo a:hover {
	color:#000;
	}
.active {
background-color:#ccc !important;
color:#000000;
}
</style>
<script>
$(document).ready(function() { 
$('.label_copy').hide();
lhash=location.hash
if(location.hash==""){
      $("#GenInfo").addClass("active");
 }
		if(lhash==""){
			lhash="#div6"
		}

		$("a[href='"+lhash+"']").closest("div").addClass("active");
		$(lhash).show();
		
$('.show').click(function () {
    $('.label_copy').hide();
    $('#div' + $(this).attr('target')).show();
});

$('.hide').click(function () {
    $('.label_copy').hide();
  
});
});
</script>
</head>
<body>

<div id="ForMembers" class="ForMembers" >
    <span style="font-size:20px; font-family:Georgia, 'Times New Roman', Times, serif; color:#FFF;">Members</span><br/>
  
   <a id="1" class="show subcontact" target="1" style="font-size:12px;">Report</a><br/>

 <a id="7" class="show subcontact" target="7" style="font-size:12px;">Member </a><br/>
 
  <a id="8" class="show subcontact" target="8" style="font-size:12px;">Patient </a>
  </div>
    	<div id="Coverage">
    	
    	  <span style="font-size:20px; font-family:Georgia, 'Times New Roman', Times, serif; color:#FFF;">Coverage</span><br/>
   	 
   	  <a id="3" class="show subcontact" target="3" style="font-size:12px;">Get a Quote</a><br/>
   
    <a id="4" class="show subcontact" target="4"  style="font-size:12px;">Apply for Coverage</a><br/>
    	   
    	   <a id="5" class="show subcontact" target="5"  style="font-size:12px;">Find an Agent</a>
  	    
    	</div>
    	
    	<div id="GenInfo">
    <span style="font-size:20px; font-family:Georgia, 'Times New Roman', Times, serif; color:#FFF;">General Information</span><br/>
    	
    	 <a id="6" class="show subcontact" target="6" style="font-size:12px;">Contact us by email</a>
    	
    	</div>
   
	

    
 
<div id="div1"  class="label_copy">
claim info
</div>
  
 
  
    <div id="div3" class="label_copy">
quote info
    </div> 
      <div id="div4" class="label_copy">
apply info
    </div>
      <div id="div5" class="label_copy">
agent info
    </div>
      <div id="div6" class="label_copy">
contact info
    </div>
      <div id="div7" class="label_copy">
  <p>member info</p>
    </div>
      <div id="div8" class="label_copy">
   <p>A patient info</p>
    </div>
</body>
   


</html>

Open in new window

0
Comment
Question by:smfmetro10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40233204
Wasn't all this sorted in another question I answered - seem to be going backwards

Replace your first jquery block with this

$(document).ready(function() { 
    $("div a").click(function() {
        $("#ForMembers,#Coverage,#GenInfo").removeClass("active")
        $(this).closest("div").addClass("active")
        var v = $(this).attr("id");
        $("#recipientId").val(v);
    });
});

Open in new window

0
 

Author Closing Comment

by:smfmetro10
ID: 40234409
Thank You!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

719 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