views:

29

answers:

1

I would like to change the variable x to 3 every time the window gets resized.

$(document).ready(function ()
{
    var x = $("#display_piece_big_frame").offset().left;

    $(window).bind("resize", function()
    {
        x = 300;
    });
});

Note: x cannot be put outside the document.ready function because it uses jQuery.

+4  A: 

Place the variable x outside the ready function. Put it in the global scope, or in an object in the global scope.

var x = 1;
$(document).ready(function(){
  $(window).bind('resize', function() { x = 3; });
});
Marius
"x" cannot be put outside the document.ready function because it uses JQUERY.
TIMEX
put x without assigning value and assign value inside document ready
rahul