我知道如何使用jQuery遍歷XML元素的兒童:jQuery檢查xml元素是否有孩子?
$(this).children('tag_name').each(function() {
});
有沒有一種方便的方式來簡單地測試如果一個元素有孩子嗎?事情是這樣的不正確的代碼:
$(this).hasChildren('tag_name') //returns true or false
我知道如何使用jQuery遍歷XML元素的兒童:jQuery檢查xml元素是否有孩子?
$(this).children('tag_name').each(function() {
});
有沒有一種方便的方式來簡單地測試如果一個元素有孩子嗎?事情是這樣的不正確的代碼:
$(this).hasChildren('tag_name') //returns true or false
使用此方法:
var hasChildren = $(this).children('tag_name').length > 0;
$(this).find('tag_name').length > 0
所有後代之間尋找 $(this).children('tag_name').length > 0
爲inmediate兒童
你可以這樣做 -
有沒有簡單的方法來測試一個元素是否有孩子?
如果您沒有設置特定的元素名稱,這是最直接的方法。
this.childElementCount > 0