i got a JS Script that shows/hides share icons, wheren a sharebutton is clicked.
The page has multiple sharebuttons on the page. How can I turn it to only toggle those elements in the same row as the button? Currently my Script toggles ALL icons at once.
For example: imagine a joblisting with a sharebutton for every job.
Currently im using
function hideInactive() {
var x = document.getElementsByClassName('social_icons');
console.log(x.length);
for (let i = 0 ; i < x.length; i++) {
if (x[i].style.display === "inline") {
x[i].style.display = "none";
} else {
x[i].style.display = "inline";
}
}
}
But this obviously toggles all icons at once. and not only the relevant ones.
2
Answers
Use jQuerys
closest()
function to find your parent row, then you can select all buttons in that parent row: