How to build a conditional selector?

  • 0
    There is a set of elements with attributes of the form id = 10
    How do I construct a selector to select elements with id & gt; 10 ?
    JavaScript Anonymous, Aug 12, 2020

  • 3 Answers
  • 0

    <li id="1"></li>
    <li id="2"></li>
    <li id="3"></li>
    <li id="4"></li>
    <li id="5"></li>
    <li id="6"></li>
    <li id="7"></li>
    <li id="8"></li>
    <li id="9"></li>
    <li id="10"></li>
    <li id="11"></li>
    <li id="12"></li>

    const elements = [...document.querySelectorAll('li')];
    console.log(elements.filter(li => +li.getAttribute('id') >= 10));

  • 0
    elem:not([id="1"]):not([id="2"]):not([id="3"]):not([id="4"]):not([id="5"]):not([id="6"]):not([id="7"]):not([id="8"]):not([id="9"]) {

  • 0
    possible with prefixes. it will work better this way.

    you can walk through all the elements


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