Trying to create a list with collapsible headlines, however when I click inside the list it collapses.
Here's my javascript, (I don't know jQuery yet)
function comFunc() {
document.getElementById("Community").classList.toggle("show");
document.onclick = function(event) {
var x = document.getElementById("Community");
var y = document.getElementById("comarrow");
if (x.classList.contains("show")) {
y.classList.remove("glyphicon-menu-right");
y.classList.add("glyphicon-menu-down");
} else {
y.classList.remove("glyphicon-menu-down");
y.classList.add("glyphicon-menu-right");
}
}
window.onclick = function(event) {
var x = document.getElementById("Community");
var y = document.getElementById("comarrow");
if (!event.target.matches('.resbtn')) {
x.classList.remove('show');
y.classList.remove("glyphicon-menu-down");
y.classList.add("glyphicon-menu-right");
}
}
}
I tried to using "||" as in
if (!event.target.matches('.resbtn' || '.dropdown-content')) {
but that didn't seem to work.
Any thoughts?
Aucun commentaire:
Enregistrer un commentaire