Hi there,
I’m using this script and added this to Layout JS:
for (var i = 0, len = document.querySelectorAll(`div.facetwp-facet-product_categories > div.facetwp-depth`).length; i < len; i++) {
document.querySelectorAll(`div.facetwp-facet-product_categories > div.facetwp-depth`)[i].classList.add("visible");
};
for (var i = 0, len = document.querySelectorAll(`div[data-value="acupunctuur"] > span.facetwp-expand`).length; i < len; i++) {
document.querySelectorAll(`div[data-value="acupunctuur"] > span.facetwp-expand`)[i].innerHTML="[-]"
};
for (var i = 0, len = document.querySelectorAll(`div[data-value="sanopharm"] > span.facetwp-expand`).length; i < len; i++) {
document.querySelectorAll(`div[data-value="sanopharm"] > span.facetwp-expand`)[i].innerHTML="[-]"
};
The script works when added to the console directly, but doesn’t run from custom Layout JS. What am I doing wrong?
Edit: I’m using a script to open two parents but leaving the rest collapsed. See my last post with the working code: [Solved] FacetWP script to open only specific parents