Tell me what I am doing wrong and what my mistake is ... I cannot pass the same function to two methods:

In this form it works only when the page is loaded, and when resize-does not work.

$(document).ready(calcHeight()); function calcHeight(){ let bgWidth=$(".wrap").width(); let bgHeight=bgWidth/100*83.4; $(".wrap").height(bgHeight); } $(window).resize(calcHeight()); 

But if you write as follows, it works .... but why and how to do it right?

 $(document).ready(calcHeight()); function calcHeight(){ let bgWidth=$(".wrap").width(); let bgHeight=bgWidth/100*83.4; $(".wrap").height(bgHeight); } $(window).resize(function(){ let bgWidth=$(".wrap").width(); let bgHeight=bgWidth/100*83.4; $(".wrap").height(bgHeight); }); 
  • one
    use the reference to the function and not its call - $(document).ready(calcHeight); not $(document).ready(calcHeight()); - Stranger in the Q

1 answer 1

 $(window).resize(function() { calcHeight() });