2014-10-10 88 views
0

嗨,任何人都可以幫助我獲取jquery中沒有類的所有元素。刪除沒有類的jquery元素

我有一個名單,我想所有的沒有一個類,並刪除它

這裏是我的代碼到目前爲止

var listTableHeaders = $("ROI-List").find("th"); 
listTableHeaders.not(".sorting").remove(); 

我意識到,還有其他類不是「排序」如在此PIC看出

enter image description here

我可以只除去未「排序」的元件或「sorting_disabl其他編輯「,但我不確定是否有其他類,所以刪除沒有任何類的th會更方便。

謝謝

+0

[jQuery的可能重複:選擇一個元素當它沒有類名](http://stackoverflow.com/questions/9042289/jquery-select-an-element-only-when-it-has-no-class-name) – melancia 2014-10-10 17:52:51

+1

'$('#ROI -List th:not([class])')。remove()'。對於整行'$('#ROI-List th:not([class])')。closest('tr')。remove()' – melancia 2014-10-10 17:56:14

回答

3

你可以過濾它

listTableHeaders.filter(function(){ 
    return !$(this).is('[class]'); 
}).remove(); 
+0

我想你打敗了我幾秒鐘:) Upvoted – frenchie 2014-10-10 17:55:50

1

事情是這樣的:

$("ROI-List").find("th").each(function() { 

    if (!$(this).prop('class').length) { 

     $(this).remove(); 
    } 
}); 
1

我相信這會爲你想要做的工作:

$("ROI-List").find("th:not([class])").remove();