View Full Version : MSIE Mac won't use my javascript for display: none or block.

04-12-2005, 12:40 AM
I don't know if this is just an issue with IE for Mac or if the other browsers are just being forgiving of some oversight on my part. Can someone shed some light on this for me please?

The code is super-simplistic, I think...

<script language="javascript">
function showElement(tagID) {
var welcome = document.getElementById('welcome');
var bio = document.getElementById('bio');
var media = document.getElementById('media');
var contact = document.getElementById('contact');
var myTag = document.getElementById(tagID);
welcome.style.display = "none";
bio.style.display = "none";
media.style.display = "none";
contact.style.display = "none";
if (myTag.style.display == "none") {
myTag.style.display = "block";

...activated by this...

<a class="navlink" onMouseOver="javascript:showElement('welcome')" >|Welcome|</a>
<a class="navlink" onMouseOver="javascript:showElement('bio')" >|Bio|</a>
<a class="navlink" onMouseOver="javascript:showElement('media')" >|Media|</a>
<a class="navlink" onMouseOver="javascript:showElement('contact')" >|Contact|</a>

...and the css sheet has, among other things, "display: block;" on for the "welcome" div and "display: none;" on the rest of them.

It looks like it should work to me, and it does, on most things. Mac IE is the only problem I've had so far. Can anyone either help me fix it, or tell me that IE Mac is just being buggy, or if I'm completely useless and "go away"?

Thanks a lot, I appreciate it. :thumbsup:

04-13-2005, 03:12 PM
I have 0 VIEWS and I'm on page three. *sigh*. That's kinda no good. No one is even going to read my problem?

I usually hate bumps, but... *bump*

sorry :(

04-13-2005, 04:27 PM
if (myTag.style.display == "none") {

If there is no style set inside your tag, there is no style to be found. If you have set the CSS using an embeded or external you should use something else to get the CSS attributes.

Well, anyway, you may also try this:

if ((myTag.style.display=='')||(myTag.style.display == "none")) {


if ((myTag.style.display==null)||(myTag.style.display == "none")) {

And: use <script type="text/JavaScript"> instead of <script language="javascript">. The latest is deprecated.

04-14-2005, 05:43 AM
i didn't show the code for the divs,, since basically they're <div id=blah>content</div> with the style stuff in the style.css sheet.

i will try the script = script type="text/JavaScript" though, thanks for the tip about deprecation.

display refers to the css property display:

#divname {display: none;

for example.

the display is never null, it's either "none" or "block". This works in all other browsers. an example is at www.mitchfactor.com


04-14-2005, 08:41 AM
I repeat. If the CSS property is set otherwise than locally, inside the tag, that means there is no style="attribute:value" so that object.style.attribute='' has no meaning.

If the CSS attributes are set embeded or external, to get the style properties you have to use other methods (IE and Moz have different behaviuor on that):

function getStyle(el,styleProp)
var x = document.getElementById(el);
if (window.getComputedStyle)//Mozilla, DOM compliant
var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
else if (x.currentStyle)//IE
var y = eval('x.currentStyle.' + styleProp);
return y;

04-14-2005, 09:50 AM
var y = eval('x.currentStyle.' + styleProp);

var y = x.currentStyle[styleProp];

04-14-2005, 10:09 AM
eerrr yes, sorry.... I have copy/paste the code from one of my elder test pages... I now also avoid eval() method...

04-14-2005, 10:11 AM
On the other hand, maybe you don't need that code. I insist, the below code should also be used in your case

if ((myTag.style.display=='')||(myTag.style.display == 'none')) {

the '' is not a double quote, there are 2 simple quotes there...