I have the following code:
document.getElementById("container").addEventListener("scroll", function () {
console.log("scroll Event...");
});
function WrapText() {
document.getElementById("container").classList.add("WrapText");
}
div {
width:100%;
height:50px;
background-color:yellow;
overflow: auto;
}
div.WrapText{
height:100%;
}
<div id="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<button onClick="WrapText()">Wrap Text</button>
When I do Scroll
I detect it through the onScroll event and I display a message in console.
Now, when I press the Wrap Text
button I re-dimension the window and adjust it to the text.
The problem:
How to detect the re-sizing event of a <div>
through addEventListener()
, that is, how to know when re-dimensioning an element in the DOM ?
NOTE:
It is important that the solution is through an event attached to the <div id="container">
element as we do with the onScroll event and not the onClick event applied to the <button>
element .