Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

jQuery resize problem

Featured Replies

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 by funsella

$(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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.