JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test1"><img src="img.jpg" /></div>
<div id="test2">Hello</div>
JavaScript
function hasImage(id) {
var childElements = document.getElementById(id).childNodes;
for (var i = 0; i < childElements.length; i++) {
if (childElements[i].localName != null && childElements[i].localName.toLowerCase() == "img") {
return true;
}
}
return false;
}
alert(hasImage('test1'));
alert(hasImage('test2'));