/    Sign up×
Community /Pin to ProfileBookmark

Only ONE submenu open

**close all submenus**
https://jsfiddle.net/h2sxzLr9/9/

**toggle submenus works**
https://jsfiddle.net/h2sxzLr9/12/

**toggle and close other submenus does not work**
https://jsfiddle.net/h2sxzLr9/15/

“`
const btns = document.querySelectorAll(‘.btn’);

alert(“toggle does not close other boxes”)

btns.forEach(function(elem) {
elem.nextElementSibling.classList.remove(“open”)
});

btns.forEach(
function(elem) {
elem.addEventListener(‘click’, function(evt) {
var box = evt.target.nextElementSibling
box.classList.toggle(‘open’);
}, true);
}
);
“`

How do I get these script work together? I guess it must be controlled by one single function? How?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@sibertauthorSep 06.2019 — I think I found it:

https://jsfiddle.net/xnw6qbtu/2/
×

Success!

Help @sibert 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 4.26,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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