December 4, 201114 yr Hi, I am playing around with jQuery and I am a little stuck $(document).ready(function(){ var Main = $('#box'); var boxWidth = Main.width(); $("#box").ready(function(){ $("button").click(function(){ alert( boxWidth ); }); }); }); I am able to calculate the width of the box but when I resize the window and try and calculate is gives me the same result even though the box has resized. If i refresh the browser after resizing the window and then bush the button it gives me the correct result. any help would be appriciated Its all fixed now, was a simple silly error Edited December 4, 201114 yr by funsella
December 4, 201114 yr $(document).ready only fires once - when the page is first loaded. If you want it to keep updated then try something like: $(function() { $("button").click(function(){ var Main = $('#box'); var boxWidth = Main.width(); alert(boxWidth); }); });
Create an account or sign in to comment