如果给定节点具有子节点,则HTML hasChildNodes()属性将返回true,否则将返回false。空白行或空白也被视为子节点,因此它在空白行或空白中也返回true。先决条件DOM(文档对象模型)
参数:
无需参数。
返回值:HTML nodeValue属性返回以下类型的值。
真正如果给定的节点具有子级或空格或空白行。
假如果给定的节点没有任何孩子。
用法
node.hasChildNodes()
示例1:在以下段落中,标记没有任何内容,因此返回false
// utility function to demonstarte hasChildNode Property
function exampleFunction() {
// var x used to get the information of those node
// for which you want to perform
// hasChildNode properties
var res =
document.getElementById("divId").hasChildNodes();
document.getElementById("GeeksForGeeks"+
).innerHTML = res;
}
click to know the paragraph tag has any child node
输出:
例2:在下面的段落中,标签有一个消息,因此返回true
// utility function to demonstarte hasChildNode Property
function exampleFunction() {
// var x used to get the information of those nodes
// for which you want to perform
// hasChildNode properties.
var res =
document.getElementById("divId").hasChildNodes();
document.getElementById("GeeksForGeeks"+
).innerHTML = res;
}
Hello geeksforgeeks
click to know the paragraph tag has any child
输出:
支持的浏览器:DOM click()方法支持的浏览器如下:
谷歌浏览器
苹果Safari
火狐浏览器
Opera
边