refresh or trigger javascript on window resize -


i using javascript make 2 child div's same height in parent div:

$(function(){ var leftheight = $('.leftblock').height(); var rightheight = $('.rightblock').height(); if (leftheight > rightheight){ $('.rightblock').css('height', leftheight); } else{ $('.leftblock').css('height', rightheight); } }); 

when resize window 1 of divs getting lot longer again javascript doesn't work anymore. placed exact same script again in window resize function , solves problem!

$(window).resize(function(){ // same script above again }); 

my question; there cleaner way can use script once refresh or trigger script again on window resize?

sure, declare function , use in both handlers:

function resizedivs() {     var leftheight = $('.leftblock').height();     var rightheight = $('.rightblock').height();     if (leftheight > rightheight){ $('.rightblock').css('height', leftheight); }     else{ $('.leftblock').css('height', rightheight); } } $(resizedivs); $(window).resize(resizedivs); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -