Home  >  Article  >  Web Front-end  >  How to Target Elements with IDs Containing Specific Text in CSS?

How to Target Elements with IDs Containing Specific Text in CSS?

DDD
DDDOriginal
2024-10-30 20:45:03569browse

How to Target Elements with IDs Containing Specific Text in CSS?

CSS Selector to Target Elements with IDs Containing Specific Text

You have elements with IDs like the following:

<code class="html"><a> element with id = someGenerated Some:Same:0:name</a>
<a> element with id = someGenerated Some:Same:0:surname</a>
<a> element with id = someGenerated Some:Same:1:name</a>
<a> element with id = someGenerated Some:Same:1:surname</a></code>

You need a CSS selector to retrieve the elements with IDs containing "name". Using a[id*='Some:Same'] alone would return all elements, which isn't what you want.

Instead, use the following selector:

<code class="css">a[id*='Some:Same'][id$='name']</code>

This selector combines the substring and ending matches. It will select all elements with IDs containing "Some:Same" and ending in "name". This will accurately isolate the desired elements.

The above is the detailed content of How to Target Elements with IDs Containing Specific Text in CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn