I am trying to figure out a way to detect when a div element is resized and resize several other associated elements in the same class as it. I learned that the onresize
event only works on the body but not individual elements.
I did discover ResizeObserver
and there was this example ->How to detect DIV's dimension changed?
<html>
Width: <output id="width">0</output><br>
Height: <output id="height">0</output><br>
<textarea id="textbox">Resize me</textarea><br>
</html>
<script>
function outputsize() {
width.value = textbox.offsetWidth
height.value = textbox.offsetHeight
}
outputsize()
new ResizeObserver(outputsize).observe(textbox)
</script>
As you can see the observer is passed the object by name and a call back, but I am trying to figure out way to pass the call back an element. The example above the specific the element name (textbox) is in the function, but I'd like to pass it as an input variable. something like...
new ResizeObserver(outputsize(self)).observe(self)
I feel like this should be easy but I am missing it.