/    Sign up×
Community /Pin to ProfileBookmark

change div class on click

Hi,

I have a tree menu on my site.

The problem is the when I click on one of the closed menu points, the opened one doesnt close.

[CODE]if (firstChild.className.search(/open/) >= 0){
tg.className = tg.className.replace(‘open’, ‘closed’);
firstChild.className = firstChild.className.replace(‘open’, ‘closed’);
} else {
tg.className = tg.className.replace(‘closed’, ‘open’);
firstChild.className = firstChild.className.replace(‘closed’, ‘open’);
}[/CODE]

The first child is the menu point that should open or close.

Since I actualy have only two points that open as a tree menu, I would need to change the div class of the one that is already opened.

Any thoughts are appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinFeb 19.2010 — I'd be careful to use "open" or "close" anywhere in code.

Reserved words, you need to scramble them to similar "open1" "close1"

Also, something I have seen never looked into it, cant think exactly the method-

stoppropogation, or stopbubble... something

I think that may be what you need here
×

Success!

Help @sudec 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 5.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...