CSS selector (id contains part of text)

I have a question. I have elements something like this:

<a> element with id = someGenerated Some:Same:0:name

<a> element with id = someGenerated Some:Same:0:surname

<a> element with id = someGenerated Some:Same:1:name

<a> element with id = someGenerated Some:Same:1:surname

I need CSS selector to get names. The problem is that I don't know how to get it. I tried a[id*='Some:Same'] - it returned all <a> elements. After I can get elements which id ends with name. But I don't like this idea. I think that it can be done with some other selector.

157152 次浏览

我看到的唯一选择器是 a[id$="name"](所有的链接都以“ name”结尾) ,但是它没有应有的限制。

试试这个:

a[id*='Some:Same'][id$='name']

这将得到所有包含 id 的 a元素

一些: 一样

并以 ID 结尾

姓名

<div id='element_123_wrapper_text'>My sample DIV</div>

The Operator ^ - Match elements that starts with given value

div[id^="element_123"] {


}

以给定值结尾的 Operator $- Match 元素

div[id$="wrapper_text"] {


}

Operator *-匹配具有包含给定值的属性的元素

div[id*="123_wrapper"] {


}