-2

In this html:

<tbody>
  <tr class="cart-item">
    <td class="image">
      <a href="listing_page/PR1"></a>
    </td>
    <th scope="row" class="info"> ... </th>
    <td class="price"> .. </td>
    <td class="actions">
      <a href="" class="">Remove from cart</a></td>
  </tr>
  <tr class="cart-item">
    <td class="image">
      <a href="listing_page/PR2"></a>
    </td>
    <th scope="row" class="info"> ... </th>
    <td class="price"> .. </td>
    <td class="actions">
      <a href="" class="">Remove from cart</a></td>
  </tr>
</tbody>

I want to select the anchor tag with "Remove from the cart". But I need it to be uniquely identified with the product code. It is listed in the tr tag which contains href with product code "listing_page/PR1".

Any ideas on how to do it with CSS?

mismas
  • 1,236
  • 5
  • 27
  • 55
  • Why not try something? – Mitya Feb 24 '20 at 12:35
  • Your title and question text do not match. Do you want to select the `td` or the link? – Paulie_D Feb 24 '20 at 12:37
  • Regardless, **you can't**. You would be trying to select UP the DOM and that's not possible with CSS. Duplicate - https://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector – Paulie_D Feb 24 '20 at 12:42

1 Answers1

2

If you are asking if you can write a CSS selector that selects an element based on the elements containing text, then the answer is no, it cannot be done.

There is one case that selects based on the content, but that selector is :empty (and it can, obviously, only be used to select the element that has no content).

You will have to use a class, an attribute or some other way of distinguishing that anchor tag, and select it in that way.

Mahatmasamatman
  • 1,537
  • 2
  • 6
  • 20