I have written JavaScript code to show and hide the div. But I got stuck when it is not working in Internet Explorer 8. It is working smoothly in other browsers, like Opera, Firefox etc.
Here is my code:
<html>
<head>
<title>Javascript Show Hide Div Visibility</title>
<style type="text/css">
</style>
<script language="javascript" type="text/javascript">
function showHideDiv()
{
var divstyle = new String();
divstyle = document.getElementById("div1").style.visibility;
if(divstyle.toLowerCase()=="visible" || divstyle == "")
{
document.getElementById("div1").style.visibility = "hidden";
}
else
{
document.getElementById("div1").style.visibility = "visible";
}
}
</script>
</head>
<body>
<div id="div1" class="divStyle">
<object width="300" height="300">
<param name="movie" value="http://www.youtube.com/v/7_6B6vwE83U">
</param>
<embed src="http://www.youtube.com/v/7_6B6vwE83U"
type="application/x-shockwave-flash"
width="300"
height="300">
</embed>
</object>
</div>
<center>
<div onclick="showHideDiv()">Click Me For show hide <div>
</center>
</body>
</html>
Try using
display
:There is a filter property
(style.filter)
that IE8 sets it toalpha(opacity=0)
. Just set it to undefined and the element pops up again.The respondents that have tested it all report that it works fine in their IE8. That would leave three options open:
Your page works just fine in Firefox 4 and Internet Explorer 8 on Windows XP.
Yours: http://jsfiddle.net/mplungjan/2KZ47/
Mine: http://jsfiddle.net/mplungjan/7bxrB/
jQuery is your best friend when working with DOM.
try: