Why doesn't style work for querySelector?

  • 0
    Tried both querySelector, both querySelectorAll and getElementsByClassName. But you still can't change the style value.

    const buttons = document.getElementsByClassName('js-toggle-card');
        for (const button of buttons) {
            button.addEventListener('click', () => {
                let tags__secondaryEl = document.querySelector('tags__secondary');
                tags__secondaryEl.style.display = 'block';
            });
        }


    This is what the compiler says:

    JavaScript Quinn Aguirre, Sep 18, 2019

  • 3 Answers
  • 0
    He says so because document.querySelector ('tags__secondary') returned null. That is, he did not find the element

    & lt; tags__secondary & gt; on your page.



    Did you mean document.querySelector ('. Tags__secondary')
    Cora Fleming

  • 0
    document.querySelector('.tags__secondary'); // точку в селекторе забыли
    Anonymous

  • 0
    add a dot in the querySelector declaration
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!