/    Sign up×
Community /Pin to ProfileBookmark

Collapse menu is quirky in Firefox

Hey guys, attached is a zip of my file.

I have a very simple [B]JS script[/B] for a collapse menu:

[code=php]function switchMenu(obj) {
var el = document.getElementById(obj);
if(el.style.display != “block”) {
el.style.display = “block”;
}
else {
el.style.display = “none”;
}
}[/code]

The script works fine in both IE6 and Firefox. However, when a menu item is clicked, its sub-menu stays open until you click the menu item again to hide it. I wanted any previously expanded sub-menus to automatically close when a NEW menu item was clicked. So I basically just set all of my sub-menus to have a display style of “none”, instead of “block” when a menu item is clicked. I changed the script to this:

[code=php]function switchMenu(obj) {
this.myvar.style.display = “none”;
this.myvar2.style.display = “none”;
this.myvar3.style.display = “none”;
this.myvar4.style.display = “none”;

var el = document.getElementById(obj);
if(el.style.display != “block”) {
el.style.display = “block”;
}
else {
el.style.display = “none”;
}
}[/code]

This script works beautifully in IE6, but now the menu won’t work AT ALL in Firefox! Any ideas?

I am typically not a javascript coder, so I’m sure there’s an easier way to achieve the effect I want without having to list all my obj ID’s, but I didn’t know how else to do it! Hopefully there’s an easy way to get it to work in firefox!

Thanks!
-heather ?

[upl-file uuid=907561fb-49f5-4a30-948b-e85f29761c6d size=2kB]collapse_menu.zip[/upl-file]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@heathercapriauthorNov 11.2005 — Can anyone help me on this one?

-heather ?
Copy linkTweet thisAlerts:
@David_HarrisonNov 11.2005 — Have a look at this, should do it. I've altered the markup a tad, for two reasons. It makes it slightly easier for the script to pick out what's what, and it's also more descriptive of the content it contains.

[upl-file uuid=33f9bd0d-47cc-42d4-a87a-fd5d9de83cb7 size=2kB]collapse_menu.zip[/upl-file]
Copy linkTweet thisAlerts:
@heathercapriauthorNov 11.2005 — David! You're awesome, that totally did it! THANK YOU!

Quick question... if I were to use a custom tag in place of the "ul" tag that you're using, what all would need to be changed in the .js file and the .css file? I don't like the ul tag because it puts in way too much space when viewed in IE. So if I were to change the html from using the ul/li tags to something like [FONT=Courier New]<div id="main"> blah </div>[/FONT], how would I then call it in the .js file? With the div's ID? Or with a class, like [FONT=Courier New]<div class="main"> blah </div>[/FONT]?

Again, thank you so much!

-heather ?
Copy linkTweet thisAlerts:
@David_HarrisonNov 11.2005 — Seems that there's a strange bug in IE, but it goes away by adding either a border or some padding to the <li>. I would really rather not alter the markup, because a nested list with headings is (in my opinion) the most appropriate markup.

I've uploaded a version that looks OK in IE now, is that OK?

[upl-file uuid=7de653d2-4e56-48eb-b27f-88048e984c08 size=2kB]collapse_menu.zip[/upl-file]
Copy linkTweet thisAlerts:
@heathercapriauthorNov 12.2005 — David, that is absolutely beautiful! You ROCK! Thank you, thank you, thank you!!

-heather ?
Copy linkTweet thisAlerts:
@David_HarrisonNov 12.2005 — No problem, happy to help. ?
Copy linkTweet thisAlerts:
@LesSydneyNov 20.2005 — Hi David,

That script is fantastic! If I wanted to put a "Home" button at the top of it, what would I need to add to make it work.

Thanks, Les
×

Success!

Help @heathercapri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...