删除父母两个div,而孩子将保持相同

时间:2017-01-30 14:25:55

标签: jquery html jquery-ui

我有一个要求,我必须将此HTML代码替换为新的HTML代码

当前的Html `

<td class="dataCol  first "><div class="requiredInput">
 <div class="requiredBlock"></div>
<select id="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" name="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" onchange="FuntomangeCorpSection();"><option value="">--None--</option><option value="Sub National">Sub National</option>
<option value="Regional Account">Regional Account</option>
<option value="Hotel">Hotel</option>
<option value="Embassy">Embassy</option>
<option value="Fleet Operator">Fleet Operator</option>
<option value="Association">Association</option>
<option value="Others">Others</option>
</select></div></td>

`

必需的HTML `

<td class="dataCol  first ">
<select id="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" name="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" onchange="FuntomangeCorpSection();"><option value="">--None--</option><option value="Sub National">Sub National</option>
<option value="Regional Account">Regional Account</option>
<option value="Hotel">Hotel</option>
<option value="Embassy">Embassy</option>
<option value="Fleet Operator">Fleet Operator</option>
<option value="Association">Association</option>
<option value="Others">Others</option>
</select></td>`

我必须删除当前的Html代码,其中包含必需的html代码,我必须将其移除到具有类名 requiredInput requiredBlock <的

请提前帮助谢谢!! !!

2 个答案:

答案 0 :(得分:0)

你需要

Unwrap,从DOM中删除匹配元素集的父节点,将匹配的元素留在原位。

$('.requiredInput').contents().unwrap();
$('.requiredBlock').remove()

答案 1 :(得分:0)

假设你有jQuery

var datacol = $('td.dataCol.first');
datacol.find('div.requiredBlock').remove();
datacol.find('div.requiredInput').contents().unwrap();