如何选择包含子项的父项具有带有特定URL的href标记

时间:2018-09-18 03:12:25

标签: jquery

我需要帮助来选择带有红色矩形的父对象,该矩形的td子对象带有红色标记的特定网址

https://user-images.githubusercontent.com/42501580/45658520-a13ed600-baef-11e8-8f1a-fdac9fb8e67d.png

2 个答案:

答案 0 :(得分:0)

您可以通过jaunty属性选择器进行操作。这样的事情可能会有所帮助

var linksToGoogle = $('a[href="http://google.com"]');

以某些URL开头的属性对您感兴趣,然后使用此属性 var

allLinksToGoogle = $('a[href^="http://google.com"]');

然后您可以使用最接近的方法来查找父对象

closest('.cart_item')

答案 1 :(得分:0)

如果您知道它永远是链接的祖父母,则可以使用parent()两次。

var link = $('a[href="http://example.com"]').parent().parent();

link.fadeOut();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr class="foo">foo1
  <td class="bar"> foo2
    <a href="http://example.com">foobar</a>
  </td>
</tr>