JSFiddle - React, Tailwind, and code Playground
HTML
<body class="example">
<div class="img-container">
<img src="https://dummyimage.com/320x120/000/fff" alt="dummy image">
<div class="img-infobox">
<p>This is a dummy image from https://dummyimage.com/</p>
</div>
</div>
</body>
JavaScript
var imgContainer = document.querySelector('.img-container');
var bodyTag = document.getElementsByTagName('body');
var bodyClassName = bodyTag.classname;
if (bodyTag.classList.contains("example")) {
imgContainer.onclick = infoBox;
function infoBox(event) {
alert('img-container has been clicked and body has class "example"');
}
}