0

I am trying to change the width of windows on dropdown change event. But I am stuck on it. The window is not resizing. here is my code:

 $(".optionextended-narrow-swap-select select").change(function() {
    $(window).resize(function(){
    // here comes the code for resize. 

     alert (""); // for now it is not event alerting

    });

});

Please help me to resize window. I just want to reduce it by 1 px just to trigger some event.

3 Answers 3

1

You can simply use:

window.resizeTo(window.innerWidth-1, window.innerHeight);

resizeTo(): The resizeTo() method resizes a window to the specified width and height.

For reducing width by 1 px: Get current width usingwindow.innerWidth and subtract 1 from it.

7
  • Can you explain your code Please that why we understand little about that resizeTo Jul 25, 2014 at 7:09
  • Not working. Does Jquery have some function to resize?
    – Faran Khan
    Jul 25, 2014 at 7:16
  • I want it inside the .change function. like when user changes the value from dropdown, then windows resize. how can it be achived
    – Faran Khan
    Jul 25, 2014 at 7:18
  • @user3800660: whoa...take it easy. i was away. in which browser have you tested this?? Jul 25, 2014 at 7:32
  • @user3800660: also there are some restrictions for this. see stackoverflow.com/a/7602372/1719752 Jul 25, 2014 at 7:35
0

you need to trigger the window resize event.

Check the below article.

How to trigger the window resize event in JavaScript?

1
  • No i need to resize the window. the link you send triggers an event after resize
    – Faran Khan
    Jul 25, 2014 at 7:25
0

Try like

$(".optionextended-narrow-swap-select select").change(function() {
$(window).trigger( "resize" );
});

This was demo How it works

fiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.