Home >Web Front-end >CSS Tutorial >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!