querySelector() where display is not none

前端 未结 3 1216
独厮守ぢ
独厮守ぢ 2021-02-20 11:29

I have a long list of

  • items I need to filter. I want the visible ones. Here\'s an example hidden one:

  • 3条回答
    •  后悔当初
      2021-02-20 12:25

      This whole thing is kind-of hacky, but you could use the :not() selector to invert your selection. Beware some browser normalize the style attribute, so you will want to include a selector for the space that may be normalized in.

      var elements = document.querySelectorAll(
          '.newSearchResultsList li:not([style*="display:none"]):not([style*="display: none"])'
      );
      
      console.log(elements);
      • hidden 1
      • visisble 1
      • hidden 2
      • visisble 2

    提交回复
    热议问题