我知道有很多關於這個的話題。在這個主題主要是關於刪除除了一個元素,但它的孩子也在刪除。用Jquery清除DIV除了一個元素和他的孩子
所以我有什麼:
<div id='maindiv'>
<div id='dont want to remove'>
<div class= "don't want to remove"></div>
<div class= "dont want to remove"></div>
</div>
<div id="want to delete"></div>
</div>
我試圖用jQuery做到這一點:
$('#maindiv').find('*:not("#dont want to remove")').remove();
當我做到這一點我有這個沒有任何子女。
<div id='maindiv'>
<div id='dont want to remove'>
</div>
</div>
感謝您的關注。祝你今天愉快。
我想你」重新嘗試保留「不想刪除」的類(儘管這在技術上是多個類)但是你使用'#'來檢查ID。使用諸如'.dontWantToRemove'之類的'.'來選擇一個類。 – DBS