View Full Version : Javascript to make the div visible in IE

09-02-2007, 10:41 PM

I was wondering if anybody knew the proper coding in order to make a Div visible if the users browser is IE?

I have a situation on my site that involves an iframe opening inside a hidden div on hover. Apparently there is a hover bug in IE that doesn't allow this action.

I have read the solution is;

The IE7 :hover bug can be mitigated by placing a hidden div behind the element. Use javascript to make the div visible if the browser is IE 7. The div needs to be wider & higher than the element and must have a background-color. Add filter: (opacity=1) if you don't want the div to be seen.

The net result here is that when the mouse is moved from element it hits the div, which fires the mouseout event (removes the :hover alteration).

Remember to hide the div again on mouseout.

Does anybody know how this is done?

Thanks in advance, any help is appreciated!

09-03-2007, 06:38 AM
<div id="eg"></div>

document.getElementById('eg').style.display = 'block';
document.getElementById('eg').style.visibility = 'visible';

09-03-2007, 07:20 AM
If you want something visible only in IE then set it as hidden in the stylesheet and then you can the following code to make it visible in IE (which runs JScript instead of JavaScript and therefore understands JScript conditional comments):

@if (@_jscript)
document.getElementById('eg').style.visibility = 'visible';
@end @*/

If you specifically need to test for IE7 then add a test for @_jscript_version >= 5.6 to the if statement.