Welcome to WebmasterWorld Guest from 3.227.233.6

Forum Moderators: open

Message Too Old, No Replies

Show/Hide script not working on IE

     
12:06 am on Nov 11, 2011 (gmt 0)

New User

5+ Year Member

joined:Nov 11, 2011
posts: 1
votes: 0


Hello,

I'm using a script to Show/Hide some divs in order to achieve a dropdown menu effect but it isn't working on IE although it works fine on Firefox and Chrome.

Can anyone please help me adapt it so that it works on IE?


<script type="text/javascript">
visibleDiv1 = "";
visibleDiv2 = "";
visibleDiv3 = "";
visibleDiv4 = "";
function showHide1(elementid1){
if (document.getElementById(elementid1).style.display == 'none'){
document.getElementById(elementid1).style.display = '';
if(visibleDiv1 != ""){
if(visibleDiv1 != elementid1){
document.getElementById(visibleDiv1).style.display = 'none';
}
}
visibleDiv1 = elementid1;
} else {
document.getElementById(elementid1).style.display = 'none';
}
}
function showHide2(elementid2){
if (document.getElementById(elementid2).style.display == 'none'){
document.getElementById(elementid2).style.display = '';
if(visibleDiv2 != ""){
if(visibleDiv2 != elementid2){
document.getElementById(visibleDiv2).style.display = 'none';
}
}
visibleDiv2 = elementid2;
} else {
document.getElementById(elementid2).style.display = 'none';
}
}
function showHide3(elementid3){
if (document.getElementById(elementid3).style.display == 'none'){
document.getElementById(elementid3).style.display = '';
if(visibleDiv3 != ""){
if(visibleDiv3 != elementid3){
document.getElementById(visibleDiv3).style.display = 'none';
}
}
visibleDiv3 = elementid3;
} else {
document.getElementById(elementid3).style.display = 'none';
}
}
function showHide4(elementid4){
if (document.getElementById(elementid4).style.display == 'none'){
document.getElementById(elementid4).style.display = '';
if(visibleDiv4 != ""){
if(visibleDiv4 != elementid4){
document.getElementById(visibleDiv4).style.display = 'none';
}
}
visibleDiv4 = elementid4;
} else {
document.getElementById(elementid4).style.display = 'none';
}
}
</script>


Thanks!
4:08 am on Nov 11, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


You only need one function

function showHide(id){
var el = document.getElementById(id);
if ( el.style.display == 'none'){ el.style.display = ''; }
else { el.style.display = 'none'; }
}

If that does not fix it, check html and css to see if something other than style.display may be hiding the div.

Welcome