0

I have a question, I want to create somewhat something like Tab. First all Contents are display: none, Then I create a code for toggling the Contents, This is my code, It works like a charm :

showOrHide = (target) => {
    if (document.getElementById(target).style.display == 'block') {
        document.getElementById(target).style.display = 'none';
    } else {
        document.getElementById(target).style.display = 'block';
    }
}

But user can show tabs simultaneous, So I want to force user to see only 1 content at moment. So I added this to when a link clicked, First all contents disappear and then show the item was clicked, but It doesn't works and show nothing to me after adding this line of code to the function above (.subLists is a class for all contents) :

showOrHide = (target) => {
    document.querySelectorAll('.subLists').style.display = 'none'; // This
    if (document.getElementById(target).style.display == 'block') {
        document.getElementById(target).style.display = 'none';
    } else {
        document.getElementById(target).style.display = 'block';
    }
}
  • 1
    `.querySelectorAll()` returns a **list** of elements, and you have to explicitly iterate through the list to operate on each element individually. – Pointy Mar 25 '18 at 13:21
  • @Pointy Thanks ... –  Mar 25 '18 at 13:24

0 Answers0