Home  >  Article  >  Web Front-end  >  How to Select Elements with IDs Containing a Specific String and Ending with a Specific Text?

How to Select Elements with IDs Containing a Specific String and Ending with a Specific Text?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 18:40:02341browse

How to Select Elements with IDs Containing a Specific String and Ending with a Specific Text?

CSS Selector: Retrieving Elements with IDs Containing a Specific String

Your question pertains to acquiring all elements with IDs containing a portion of a given text, in this case, "Some:Same". While you've attempted to use "a[id*='Some:Same']", it returns all elements with IDs containing "Some:Same", which includes unwanted results.

To narrow down the selection, consider the following CSS selector:

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

This selector will retrieve all "a" elements whose IDs contain the text "Some:Same" and additionally end with the text "name". The "=" operator in "id='Some:Same'" indicates that the ID should contain "Some:Same" anywhere within its value, while "$=" in "id$='name'" ensures that the ID ends with "name".

By employing this refined selector, you can effectively extract only those elements you're interested in. This approach offers a more targeted selection mechanism compared to your previous attempt.

The above is the detailed content of How to Select Elements with IDs Containing a Specific String and Ending with a Specific Text?. 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