JavaScript Variable width won't change after browser resize

I have two li's which, by using javascript, is the same width of a certain li. The li is fluid css so it changes according to the browser width. The li becomes the same width as the other li when I load the page.

When I resize the browser, the width of the li doesn't change until I reload the page. How can I have my li automatically resize when the browser resizes instead of changing when it loads the page?

var width = $('li.more').width();
$('li.more ul li').css({'width':width+'px'});
Answer:1

You could use $(window).resize to achieve this:

$(window).resize(function() {
  width = $('li.more').width();
  $('li.more ul li').css({'width':width+'px'});
});

Here's a jsFiddle example of resize being used.

Answer:2

<ul id="bad-drifting"> <li>text</li> </ul> http://jsfiddle.net/wZ8MC/2/ jQuery(document).ready(function() { if (jQuery('#bad-drifting').has('em')) { jQuery('#...

<ul id="bad-drifting"> <li>text</li> </ul> http://jsfiddle.net/wZ8MC/2/ jQuery(document).ready(function() { if (jQuery('#bad-drifting').has('em')) { jQuery('#...

I am merely looking for some help as a newbie learning webdesign, please understand I am still in the very early stages of learning when answering my question. I have the following: <script src="...

I am merely looking for some help as a newbie learning webdesign, please understand I am still in the very early stages of learning when answering my question. I have the following: <script src="...

  1. javascript jquery image carousel
  2. jquery script for zooming image on mouseover
  3. javascript jquery image

I am fairly new to using SugarCRM and I am just trying to do some validation on a form page I have. I am simply trying to get the value of my dropdown, and perform my error if it is equal to "None" ...

I am fairly new to using SugarCRM and I am just trying to do some validation on a form page I have. I am simply trying to get the value of my dropdown, and perform my error if it is equal to "None" ...

  1. variable dropdown selected value

How I have a basic javascript registration form which sends the password that an user has filled to a secure axis2 web service (which stores the salted hash of the password in a database). Mu ...

How I have a basic javascript registration form which sends the password that an user has filled to a secure axis2 web service (which stores the salted hash of the password in a database). Mu ...

  1. secure client javascript
  2. javascript secure websocket client example
  3. javascript secure websocket client