How to get CSS to select ID that begins with a string (not in Javascript)?

前端 未结 4 477
心在旅途
心在旅途 2020-12-07 08:55

If the HTML has elements like this:

id=\"product42\"
id=\"product43\"
...

How do I match all of those id\'s starting with \"product\"?

4条回答
  •  日久生厌
    2020-12-07 09:21

    [id^=product]
    

    ^= indicates "starts with". Conversely, $= indicates "ends with".

    The symbols are actually borrowed from Regex syntax, where ^ and $ mean "start of string" and "end of string" respectively.

    See the specs for full information.

提交回复
热议问题