Created
April 9, 2023 19:33
-
-
Save JosephNC/6d4aee1d45a62fbf953aabd31a5ba4e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const backToCollections = document.querySelector(".back-to-collections"); | |
console.log(backToCollections); | |
const listParentCollections = () => { | |
backToCollections.style.display = "none"; | |
document.querySelectorAll(".collection-grid-item").forEach((elm) => { | |
let aTag = elm.querySelector("a"); | |
let parentId = elm.dataset.parent; | |
let childrenIds = elm.dataset.children; | |
if (parentId != "0") { | |
elm.style.display = "none"; | |
} else { | |
elm.style.display = "block"; | |
aTag.href = "javascript:;"; | |
aTag.addEventListener("click", (e) => { | |
e.preventDefault(); | |
if (childrenIds.length <= 0) return; | |
let children = childrenIds.split(","); | |
children.forEach((v) => { | |
let el = document.querySelector(`[data-parent="${v}"]`); | |
if (el == null) return; | |
el.style.display = "block"; | |
}); | |
backToCollections.style.display = "block"; | |
elm.style.display = "none"; | |
// Remove event EventListener | |
aTag.removeEventListener("click", () => {}, false); | |
return false; | |
}, false); | |
} | |
}); | |
} | |
backToCollections.querySelector("a.back-btn").addEventListener("click", (e) => { | |
e.preventDefault(); | |
listParentCollections(); | |
return false; | |
}, false); | |
listParentCollections(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment