Can I use a regular expression in querySelectorAll?

后端 未结 2 1451
情话喂你
情话喂你 2020-11-30 03:15

On a page I\'m doing I will be ending up with custom link elements like this:



        
2条回答
  •  无人及你
    2020-11-30 03:29

    You can't really use a regular expression in a selector but CSS selectors are powerful enough for your need with a "starts with" syntax inspired by regexes.

    You can use a substring matching attribute selectors : link[type^=service]

    Reads "Nodes of type link with an attribute type starting with "service"

    From the formal specification:

    [att^=val]

    Represents an element with the att attribute whose value begins with the prefix "val". If "val" is the empty string then the selector does not represent anything.

    Working JSFiddle

提交回复
热议问题