Reputation: 71
<div id="pl6" style="height: 123px; width: 135px;float:left" onmousedown="test(6);" ondrop="dropIt(event,6);" ondragover="event.preventDefault();">
<img src="6.gif" draggable="true" ondragstart="dragIt(event,6);" id="pic6" />
</div>
I want to check if this div has an image or not using JavaScript.
Upvotes: 1
Views: 809
Reputation: 13529
Why not simply:
if(document.querySelectorAll("#pl6 img").length > 0) {
// ...
}
Upvotes: 1
Reputation: 100175
you could do:
var divEle = document.getElementById("pl6");
if( divEle.getElementsByTagName('img').length > 0 ) {
//has image element
}
Upvotes: 5