Search code examples
javascriptcss-selectorsselectors-api

How to use querySelectorAll based on length of the value


This is a rather specific question but I am trying to use querySelectorAll for all 'a' tags that have a 'href' value that is a specific length AND does not contain 'html' at the end of that value.

I understand the basics of querySelectorAll but not how to accomplish something like this...

Thank you for any help offered.


Solution

  • Currently, it's not possible to impose any sort of length restriction on attribute values using selectors.

    The closest you can get is this, without the length restriction:

    document.querySelectorAll('a[href]:not([href$="html"])');