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

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

DDD
Release: 2024-10-30 20:45:03
Original
666 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template