JSFiddle - React, Tailwind, and code Playground

HTML

<script>
function myFunction() { // Declare a function
    document.getElementById("parent").style.display = "block";
}
function myFunction1() { // Declare a function
    alert(document.getElementById("target").offsetWidth);
}
</script>

<button onclick="myFunction1()">info</button>
<button onclick="myFunction()">show</button>
<div id="parent" style="display:none;"> <div id="target"></div> </div>

JavaScript

var targetNode = document.getElementById('target');
var observer = new MutationObserver(function(){
	alert(targetNode.offsetWidth);
	}
);
observer.observe(targetNode,  { attributes: true, childList: true });