Hi,
I would like to know if there is a way to keep the script as is but also add a function to this script so that if a user clicks on another tab (div) the open tab will close on click? Please see code below:
Thanks in advance! :icon_smile:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<style>
#right-nav {
width:195px;
position:relative;
float:right;
}
#Div1 {
position:absolute;
width:400px;
background-color:#990000;
right:195px;
top:-3px;
}
#Div2 {
position:absolute;
width:400px;
background-color:#00FF00;
right:195px;
top:-3px;
}
#Div3 {
position:absolute;
width:400px;
background-color:#FFFF00;
right:195px;
top:-3px;
}
#Div4 {
position:absolute;
width:400px;
background-color:#9900FF;
right:195px;
top:-3px;
}
#Div1tab {
position:absolute;
top:10px;
float:left;
font: bold 12px Arial, Helvetica, sans-serif ;
margin-left:15px;
}
#Div2tab {
position:absolute;
top:45px;
float:left;
font: bold 12px Arial, Helvetica, sans-serif ;
margin-left:15px;
}
#Div3tab {
position:absolute;
top:85px;
float:left;
font: bold 12px Arial, Helvetica, sans-serif ;
margin-left:15px;
}
#Div4tab {
position:absolute;
top:118px;
float:left;
font: bold 12px Arial, Helvetica, sans-serif ;
margin-left:15px;
}
.Tab-Text a:link {
font: bold 12px Arial, Helvetica, sans-serif ;
text-decoration:none;
}
.Tab-Text a:visited {
text-decoration:none;
}
.Tab-Text a:hover {
text-decoration:none;
}
.Tab-Text a:active {
text-decoration:none;
}
#tabs {
width: 195px;
}
#nav-container {
position:relative;
}
#tabs {
}
</style>
<script language="javascript">
imageX1='plus';
imageX2='plus';
imageX3='plus';
imageX4='plus';
function toggleDisplay(e){
imgX="imagePM"+e;
DivX="Div"+e;
imageX="imageX"+e;
DivLink="DivHref"+e;
imageXval=eval("imageX"+e);
element = document.getElementById(DivX).style;
if (element.display=='none') {element.display='block';}
else {element.display='none';}
if (imageXval=='plus') {document.getElementById(imgX).src='fab_tabs_on.gif';eval("imageX"+e+"='minus';");document.getElementById(DivLink).title='Hide Div #'+e+'a';}
else {document.getElementById(imgX).src='fab_tabs_off.gif';eval("imageX"+e+"='plus';");document.getElementById(DivLink).title='Show Div #'+e+'a';}
}
</script>
</head>
<body>
<div id="nav-container">
<div id="right-nav">
<a title="Show Div #1a" href="javascript:toggleDisplay('1')" id="DivHref1"><img border="0" src="fab_tabs_off.gif" id=imagePM1></a>
<div style="display:none;" id="Div1"><a href="javascript:toggleDisplay('1')">CLOSE</a>
<div style="width:200px; border: 1px solid #000000;">
TEST ALL THIS GOOD STUFF RIGHT HERE 1!
</div>
</div>
<a title="Show Div #2a" href="javascript:toggleDisplay('2')" id="DivHref2"><img border="0" src="fab_tabs_off.gif" id=imagePM2></a>
<div style="display:none;" id="Div2"><a href="javascript:toggleDisplay('2')">CLOSE</a>
<div style="width:200px; border: 1px solid #000000;">
TEST ALL THIS GOOD STUFF RIGHT HERE 2!
</div>
</div>
<a title="Show Div #3a" href="javascript:toggleDisplay('3')" id="DivHref3"><img border="0" src="fab_tabs_off.gif" id=imagePM3></a>
<div style="display:none;" id="Div3"><a href="javascript:toggleDisplay('3')">CLOSE</a>
<div style="width:200px; border: 1px solid #000000;">
TEST ALL THIS GOOD STUFF RIGHT HERE 3!
</div>
</div>
<a title="Show Div #4a" href="javascript:toggleDisplay('4')" id="DivHref4"><img border="0" src="fab_tabs_off.gif" id=imagePM4></a>
<div style="display:none;" id="Div4"><a href="javascript:toggleDisplay('4')">CLOSE</a>
<div style="width:200px; border: 1px solid #000000;">
TEST ALL THIS GOOD STUFF RIGHT HERE 4!
</div>
</div>
<div id="tabs">
<div id="Div1tab" class="Tab-Text"><a href="javascript:toggleDisplay('1')">Div1</a></div>
<div id="Div2tab" class="Tab-Text"><a href="javascript:toggleDisplay('2')">Div2</a></div>
<div id="Div3tab" class="Tab-Text"><a href="javascript:toggleDisplay('3')">Div3</a></div>
<div id="Div4tab" class="Tab-Text"><a href="javascript:toggleDisplay('4')">Div4</a></div>
</div>
</div>
</body>
</html>