Home  >  Article  >  Web Front-end  >  How to Target Elements with IDs Containing \"Some:Same\" and Ending with \"name\" using CSS?

How to Target Elements with IDs Containing \"Some:Same\" and Ending with \"name\" using CSS?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 11:34:02173browse

How to Target Elements with IDs Containing

CSS Selector for Elements with IDs Containing Specific Text

Problem:

Consider HTML elements with IDs in the format "someGenerated Some:Same:0:name" or "someGenerated Some:Same:0:surname." How can we use CSS to select only those elements with IDs containing "Some:Same" and ending with "name"?

Solution:

Using the following CSS selector accomplishes this:

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

Explanation:

  • a[id*='Some:Same']: Selects all a elements whose IDs contain the string "Some:Same." The asterisks (*) are used as wildcards, allowing any characters before or after "Some:Same."
  • [id$='name']: Selects all elements whose IDs end with "name." The dollar sign ($) is used as a wildcard at the end of the string.

By combining these selectors, we can isolate the specific a elements with IDs containing "Some:Same" and ending with "name."

The above is the detailed content of How to Target Elements with IDs Containing \"Some:Same\" and Ending with \"name\" using 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