jQuery/Regex:从TD删除带有嵌套Div的Div [英] jQuery / Regex: remove Div with nested Divs from TD
本文介绍了jQuery/Regex:从TD删除带有嵌套Div的Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个TD,该TD总是包含一个div和div之外的一些文本.
I have a TD that always contains a div and some text outside the div.
div有四个嵌套的div,它们始终遵循以下结构. 我唯一感兴趣的是此TD中出现在主div之外的文本,其他所有内容都应删除.
The div has four nested divs that always follow the below structure. The only thing I am interested in is the text in this TD that appears outside the main div, everything else should be removed.
我要保留的文本各不相同,其余的结构是固定的.
The text I want to keep varies, the structure of the rest is fixed.
TD示例:
<td id="myTD">
<div id="show_status_1622327228" class="nor_addr_status" onmouseout="show_status_div(2, this);" onmouseover="show_status_div(1, this);" style="display: none;">
<div id="status_safe_1622327228" class="status_hov" onmouseout="javascript:chgcolor(2, this);" onmouseover="javascript:chgcolor(1, this);">
Text1
</div>
<div id="status_unknown_1622327228" class="status_hov" onmouseout="javascript:chgcolor(2, this);" onmouseover="javascript:chgcolor(1, this);">
Text2
</div>
<div id="status_pr_1622327228" class="status_hov" onmouseout="javascript:chgcolor(2, this);" onmouseover="javascript:chgcolor(1, this);" style="background-color: rgb(255, 255, 255);">
Text3
</div>
<div id="status_fraud_1622327228" class="status_hov" onmouseout="javascript:chgcolor(2, this);" onmouseover="javascript:chgcolor(1, this);" style="background-color: rgb(255, 255, 255);">
Text4
</div>
</div>
The only text I want to keep
</td>
我尝试了以下操作,但这不起作用-可能是因为嵌套了div:
$('#myTD').text().replace(/<div[\s\S]+?<\/div>/g, "").replace(/<a[\s\S]+?<\/a>/g, ""));
我的问题是,它保留了嵌套div(文本1,文本2,文本3,文本4)中的文本.
My problem here is that it keeps the texts from the nested divs (Text1, Text2, Text3, Text4).
推荐答案
您是否尝试过:
$("#myTD>div").remove()
这篇关于jQuery/Regex:从TD删除带有嵌套Div的Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文