 <p>Keep your code in a named <code>function</code> say - <code>changeSize</code> and call it in <code>document.ready</code> and <code>window.resize</code> as below:</p> <p><strong><a href="http://jsfiddle.net/Guruprasad_Rao/8TrTU/1628/" rel="nofollow">DEMO</a></strong></p> <pre><code>function changeSize(){ var fontSize = parseInt($("#container").width()/4)+"px"; $("#container span").css('font-size', fontSize); } $(document).ready(function() { changeSize(); $(window).resize(changeSize); }); </code></pre> <p>or just once in <code>document.ready()</code> as below:</p> <pre><code>$(document).ready(function() { $(window).resize(changeSize).trigger('resize'); }); </code></pre>