davechl
08-26-2008, 06:26 PM
Hi,
I was able to piece together a horizontal menu but found out that it doesn't work in IE7. Reading online, I learned that "onclick" doesn't work well in IE. But I'm wondering where the problem is exactly.
I have a horizontal menu bar that starts with a default/selected menu. When I click on another menu, the hilited state changes to this new menu. It works in FF2. But in IE7, each menu that I click becomes hilited, so you end up with every menu hilited instead of only the most recent one.
What do I need to make it work in IE7? :confused: Please help. Code below.
<script type="text/javascript">
function changeClass(obj) {
var lnks = document.getElementsByTagName('a');
for (var i = 0; i < lnks.length; i++) {
if (lnks[i].getAttribute('class') == "t_on") {
lnks[i].className = "t_off";
}
}
obj.className = "t_on";
}
</script>
<style type="text/css">
/*Credits: Dynamic Drive CSS Library */
/*URL: http://www.dynamicdrive.com/style/ */
.indentmenu{
font: 12px Arial;
width: 100%; /*leave this value as is in most cases*/
overflow: hidden;
}
.indentmenu ul{
margin: 0;
padding: 0;
float: left;
width: 100%; /*width of menu*/
border: 1px solid #333333; /*dark gray border*/
border-width: 1px 0;
background: #cccccc center center repeat-x;
}
.indentmenu ul li{
display: inline;
}
.indentmenu ul li a, .t_off{
float: left;
color: #000000; /*text color*/
padding: 5px 11px;
text-decoration: none;
/*border-right: 1px solid #564c66; /*dark purple divider between menu items*/
}
.indentmenu ul li a:visited{
color: #000000;
}
.indentmenu ul li a:hover{
color: #000000 !important; /*text color of active item*/
text-decoration:underline;
}
.indentmenu ul li .t_on{
color: #000000 !important; /*text color of selected item*/
padding-top: 6px; /*shift text down 1px for selected item*/
padding-bottom: 4px; /*shift text down 1px for selected item*/
background: red center center no-repeat;
}
</style>
This is the div menu (default menu 2, with red background):
<div class="indentmenu">
<ul>
<li><a href="#" class="t_off" onclick="changeClass(this);">Menu 1</a></li>
<li><a href="#" class="t_on" onclick="changeClass(this);">Menu 2</a></li>
<li><a href="#" class="t_off" onclick="changeClass(this);">Menu 3</a></li>
</ul>
</div>
I was able to piece together a horizontal menu but found out that it doesn't work in IE7. Reading online, I learned that "onclick" doesn't work well in IE. But I'm wondering where the problem is exactly.
I have a horizontal menu bar that starts with a default/selected menu. When I click on another menu, the hilited state changes to this new menu. It works in FF2. But in IE7, each menu that I click becomes hilited, so you end up with every menu hilited instead of only the most recent one.
What do I need to make it work in IE7? :confused: Please help. Code below.
<script type="text/javascript">
function changeClass(obj) {
var lnks = document.getElementsByTagName('a');
for (var i = 0; i < lnks.length; i++) {
if (lnks[i].getAttribute('class') == "t_on") {
lnks[i].className = "t_off";
}
}
obj.className = "t_on";
}
</script>
<style type="text/css">
/*Credits: Dynamic Drive CSS Library */
/*URL: http://www.dynamicdrive.com/style/ */
.indentmenu{
font: 12px Arial;
width: 100%; /*leave this value as is in most cases*/
overflow: hidden;
}
.indentmenu ul{
margin: 0;
padding: 0;
float: left;
width: 100%; /*width of menu*/
border: 1px solid #333333; /*dark gray border*/
border-width: 1px 0;
background: #cccccc center center repeat-x;
}
.indentmenu ul li{
display: inline;
}
.indentmenu ul li a, .t_off{
float: left;
color: #000000; /*text color*/
padding: 5px 11px;
text-decoration: none;
/*border-right: 1px solid #564c66; /*dark purple divider between menu items*/
}
.indentmenu ul li a:visited{
color: #000000;
}
.indentmenu ul li a:hover{
color: #000000 !important; /*text color of active item*/
text-decoration:underline;
}
.indentmenu ul li .t_on{
color: #000000 !important; /*text color of selected item*/
padding-top: 6px; /*shift text down 1px for selected item*/
padding-bottom: 4px; /*shift text down 1px for selected item*/
background: red center center no-repeat;
}
</style>
This is the div menu (default menu 2, with red background):
<div class="indentmenu">
<ul>
<li><a href="#" class="t_off" onclick="changeClass(this);">Menu 1</a></li>
<li><a href="#" class="t_on" onclick="changeClass(this);">Menu 2</a></li>
<li><a href="#" class="t_off" onclick="changeClass(this);">Menu 3</a></li>
</ul>
</div>