CSS selector (id contains part of text)

TarasLviv picture TarasLviv · Aug 28, 2012 · Viewed 113.6k times · Source

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.

Answer

CosminO picture CosminO · Aug 28, 2012

Try this:

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

This will get you all a elements with id containing

Some:Same

and have the id ending in

name