How can I call for this(or any) JS function to be run again whenever the Browser window is resized?
<script type="text/javascript"> function setEqualHeight(e) { var t = 0; e.each(function () { currentHeight = $(this).height(); if (currentHeight > t) { t = currentHeight } }); e.height(t) } $(document).ready(function () { setEqualHeight($(".border")) }) </script>
Answer: Use the addEventListener() Method You can simply use the addEventListener() method to register an event handler to listen for the browser window resize event, such as window. addEventListener('resize', ...) . The following example will display the current width and height of the browser window on resize.
The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.
Definition and UsageThe onresize event occurs when the browser window has been resized. Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.
You can use the window onresize
event:
window.onresize = setEqualHeight;
You can subscribe to the window.onresize
event (See here)
window.onresize = setEqualHeight;
or
window.addEventListener('resize', setEqualHeight);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With