删除包含特定文本的表

use*_*034 1 jquery

我想通过定位以下文本"将上述项目添加到购物车",从Jquery页面中删除下表.

我试过这个,但没有按预期工作,它删除了一个不同的父td.不确定如何仅针对此td.

$("* :contains('To add the above items to your cart')").closest('td').remove();

<td colspan="11" class="colors_backgroundlight" align="right"> 
<span>To add the above items to your cart, click the "Add" checkboxes then click "Add To Cart" &gt;&gt;&gt;</span> <input type=submit value="Add To Cart" onclick="refineResults=false;" name="checkboxes_mode_submitbtn"
Run Code Online (Sandbox Code Playgroud)

Nic*_*ver 7

你可以这样做:

$("span:contains('To add the above items to your cart')").closest('td').remove();
Run Code Online (Sandbox Code Playgroud)

任何父级将包含文本,因为它位于子元素中.你需要更具体的了解一点什么包含文本,并从那里向上移动......否则它会发现所有的父母也是如此.

或者,要非常准确,但可能是矫枉过正:

$("span:contains('To add the above items to your cart')").filter(function() {
  return this.innerHTML.indexOf('To add the above items to your cart') === 0;
}).closest('td').remove();
Run Code Online (Sandbox Code Playgroud)