我有一个变量MYCELL
,它是reference to a td
一个表的内部。
td如下所示
<td>
abc
<a href="#" class=".myLinkClass">edit</a>
</td>
现在我希望使用replace
该字符串abc
,def
但要保留链接。我以为我可以使用以下代码:
MYCELL.not(".myLinkClass").empty();
MYCELL.append("def");
但是empty()会清除整个单元格。基于此链接,我选择在.not()
语句中使用选择器
MYCELL.not(MYCELL.find(".myLinkClass")).empty();
empty (including other html-tags)
在不删除类中的任何link(<a href>
)或任何元素的情况下,如何在td中进行所有操作.myLinkClass
?
感谢您的时间
您需要使用contents()来确保还可以选择文本节点:
MYCELL.contents().filter(function() {
return !$(this).is("a"); // Only select nodes where are not <a> tags
}).remove(); // Use .remove instead
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句