user3148129
user3148129

Reputation: 13

Show/Hide JavaScript not working in IE, only in Firefox

This is the show/hide script I found online. When you click on the "view menu" image it's supposed to show the hidden div for each section. I'm not getting it to display/expand on Internet Explorer for some reason but it works fine in Firefox.
http://www.abatchoflove.com

<script type="text/javascript">
    function unhide(divID) {
        var item = document.getElementById(divID);
        if (item) {
            item.className = (item.className == 'hidden') ?'unhidden':'hidden';
        }
    }
</script>

And this was the CSS portion.

<style type="text/css">
    .hidden { display: none; }
    .unhidden { display: block; }
</style>

This is what the code looks like in the sections.

<td valign="top" bgcolor="#51BEB7">
    <a href="javascript:unhide('cookiesmenu');">
        <img src="images/cookies_nav.gif" border="0" usemap="#Map2">
    </a>
    <div id="cookiesmenu" class="hidden">
        <img src="images/cookies_menu.gif">
    </div>
</td>


Would love it if I could get a little help... Or if there is another way to go about it. Thank you in advance.

Upvotes: 1

Views: 931

Answers (2)

Milche Patern
Milche Patern

Reputation: 20452

A Internet Explorer reserved word has been used as an identifier (function or variable name).

change item by another variable name and give it a try.

http://www.ecma-international.org/ecma-262/5.1/#sec-7.6.1.1

http://www.springenwerk.com/2009/01/is-reserved-word-in-internet-explorer-6.html

IE Issue with jquery and JS

If you want to test first if this is your issue, here is your script with a different variable name.

function unhide(divID) {
    var MyItem = document.getElementById(divID);
    if (MyItem) {
        MyItem.className = (MyItem.className == 'hidden') ? 'unhidden' : 'hidden';
    }
}

http://jsfiddle.net/GvKLX/1/

Note that 'inlined javascript' is tending to disapear for security reasons. So you should consider reforming your code using javascript libraries such has jQuery. Meaning, even javascript events like 'onclick' are to become obsolete.

Upvotes: 0

Friedrich
Friedrich

Reputation: 2290

you can use

<a onclick="unhide('cookiesmenu')">

instead of

<a href="javascript:unhide('cookiesmenu');">

Upvotes: 2

Related Questions