Home >Web Front-end >CSS Tutorial >How can I use CSS selectors to target elements whose IDs contain specific text and end with a specific string?
CSS Selector for IDs Containing Partial Text
In the quest to target specific elements based on their IDs, you might encounter a scenario like the one presented in the question. The IDs in question follow a specific pattern, and the goal is to select elements with IDs containing a specific text, followed by a colon, and ending with "name."
To achieve this, the CSS selector provided in the answer serves the purpose brilliantly:
<code class="css">a[id*='Some:Same'][id$='name']</code>
Breaking down this selector:
Combining both criteria using the square brackets notation, we select only those elements whose IDs contain "Some:Same" and end with "name." This effectively targets the specific elements with IDs like "someGenerated Some:Same:0:name" or "someGenerated Some:Same:1:name."
So, instead of using a cumbersome approach that retrieves all elements and then filters them based on their IDs ending with "name," this CSS selector provides a clean and efficient way to directly select the desired elements.
The above is the detailed content of How can I use CSS selectors to target elements whose IDs contain specific text and end with a specific string?. For more information, please follow other related articles on the PHP Chinese website!