I want to have a hidden div that is shown only to MSIE browsers, I assume this is pretty straight forward but i've never done it before. I already have a function that shows and hides a div based on a button which works fine as follows; <script language="javascript"> function toggleDiv(divid){ if(document.getElementById(divid).style.display == 'none'){ document.getElementById(divid).style.display = 'block'; }else{ document.getElementById(divid).style.display = 'none'; } } </script> Code (markup): I though i'd be able to do something like this; <script type="text/javascript"> version=0 if (navigator.appVersion.indexOf("MSIE")!=-1){ temp=navigator.appVersion.split("MSIE") version=parseFloat(temp[1]) } if (version>=5.5) toggleDiv('alert') //alert is the div I wish to reveal </script> Code (markup): but it doesnt seem to work. I tested it with the button and it shows correctly, this div is as follows; <div id="alert" style="display:none"> <p class="alert">Lorem ipsum dolor sit amet.</p> </div> Code (markup): Thanks for your help
Make sure you have the javascript after you define the div. Because web pages are read top to bottom.
ok..makes sense I think I am getting there.... but if i have the following; if (version>=5.5) //NON IE browser will return 0 document.write("MSIE 5.5+!!") toggleDiv('alert') </script> Code (markup): I see the comment "MSIE 5.5+!!" in the page (when I use IE) but the div does not show up.