Che*_*hev 4 html javascript jquery dom jquery-selectors
我正在为我经常访问的论坛编写自定义脚本.它设计用于在我查看时从板上删除签名,因为它们分散注意力并且令人讨厌,并且它们无法在选项中禁用它们.
无论如何,我可以使用有用的Chrome扩展程序运行自定义脚本.我能够修改页面的任何部分,其中HTML节点具有类,ID,甚至具有一些独特信息的属性,但我似乎无法弄清楚如何使用jQuery选择和删除以下HTML.
<tr>
<td colspan="2">
<!--Signature-->
<div class="resultText">
<!-- sig -->
<div>Signature text</div>
<!-- / sig -->
</div>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
如果有一种方法我可以抓住它的父母<!--Signature-->
那将是完美的但我不确定这是否可能.
有一个类,resultText
但该类用于用户输入文本的任何位置,而不仅仅是签名中.所以我无法抓住这一点.
即使在resultText
其他地方使用该类,我仍然建议使用类选择器作为起点,否则您将在整个文档中查找注释节点.
从匹配的元素,你可以得到他们的父母的内容() ,使用过滤器()来隔离注释节点(其节点类型属性等于8
)和比较这些节点的值Signature
的字符串:
$(".resultText").parent().each(function() {
var $this = $(this);
var signature = $this.contents().filter(function() {
return this.nodeType == 8 && this.nodeValue == "Signature";
});
if (signature.length) {
// Signature found, $this is the <td> element.
$this.closest("tr").remove(); // For example.
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
620 次 |
最近记录: |