Question

The code to make a div height equal to its width below:

$('div').height($('div').width());

However if you manually resize the browser window the height will not update - you need to refresh the page. Any idea how to correct it?

Was it helpful?

Solution

You need to bind your code on the window.onresize event :

window.onresize=function(){
  $('div').height($('div').width());
};

The doc : http://www.w3schools.com/jsref/event_onresize.asp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top