The hasAttribute()
method
returns true
if the attribute exists,
otherwise false
.
element.hasAttribute(name)
Parameter | Description |
name |
Required. The name of the attribute. |
Type | Description |
Boolean |
true if the element has the attribute,
otherwise false .
|
The hasChildNodes()
method returns true if the
specified node has any child nodes, otherwise false.
The hasChildNodes()
method is read-only.
element.hasChildNodes()
NONE |
Type | Description |
Boolean |
true if the element has child nodes,
otherwise false .
|
<!DOCTYPE html>
<html>
<head>
<title>DOM Navigation</title>
<style>
h2{ margin: 0 0 10px; }
#test{
background: #ffff00;
width: 800px;
min-height: 250px;
padding: 10px 10px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="test" class="abc">
<h2>Yahoo Baba : JavaScript hasAttribute Method</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo corporis adipisci alias cupiditate officiis consequatur, fuga, amet quos numquam perferendis saepe labore dolorem reiciendis reprehenderit facilis repudiandae praesentium quis delectus voluptates, repellendus recusandae. Itaque consequuntur, corrupti quasi illum iusto perferendis autem blanditiis magni eum, repellendus architecto ratione ipsum molestiae laboriosam.
</p>
<h2>Yahoo Baba : JavaScript hasChildNodes Method</h2>
</div>
<script src="js/dom-create.js"></script>
</body>
</html>
/* JavaScript hasAttribute*/
var target = document.getElementById("test");
var find = target.hasAttribute("class");
console.log(find);
/* JavaScript hasChildNodes*/
var target = document.getElementById("test");
var find = target.hasChildNodes();
console.log(find);