Currently, I am utilizing the JavaScript function createElement to generate a new div element and then assigning its innerHTML. Following that action, I am attempting to determine the necessary width required to display the div with all of its content.
var newDiv = document.createElement("div");
newDiv.innerHTML = "My new<br/>DIV";
// Now looking to retrieve the width of the div
I have made several attempts:
Call Result
-------------------------------------- -------------
newDiv.width undefined
newDiv.scrollWidth 0
newDiv.clientWidth 0
newDiv.offsetWidth 0
newDiv.innerWidth undefined
newDiv.outerWidth undefined
newDiv.getBoundingClientRect().width 0
The section of JavaScript code responsible for creating the div is triggered by an AJAX callback; it remains unclear whether this may be contributing to the issue at hand.