-1

I have this code and I wan't to say, if the window is not smaller than 1024, don't do any of these things. How do I write this?

$(window).resize(function(){
    if ($(window).width() <= 1024) {    
        $('#right > .info').removeClass('hidden');
        $('#middle').remove();
    }
    else {
    }
});
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
Alga
  • 181
  • 1
  • 5
  • 15
  • prepend to your handler: `if ($(window).width() > 1024) return;` But then, what is supposed to do the `else` statement??? In fact, your question doesn't really make sense. Am I missing something? – A. Wolff Dec 05 '13 at 13:19
  • Else, don't remove class and else don't remove #middle? – Alga Dec 05 '13 at 13:24
  • Hope this makes it clearer: http://jsfiddle.net/m/gsp/ – Alga Dec 05 '13 at 13:27
  • Cannot log to your jsfiddle... And what could be the opposite of .remove()??? You should detach element, not remove it. The opposite of removeClass() is... addClass() – A. Wolff Dec 05 '13 at 13:29

1 Answers1

0

I am guessing what you are trying to do, is something like this:

$(window).resize(function(){
        if ($(window).width() <= 1024){ 
             $('#right > .info').removeClass('hidden');
             $('#middle').hide();
        } else {
            $('#middle').show();
            $('#right > .info').addClass('hidden');
        }
    });

The difference being, that you do not remove() (permanently remove it from the DOM), but rather hide() and show() it.

You might want to make in into a function and call it not only on resize, but also on page load.

This question might give you some inspiration: jQuery: How to detect window width on the fly?

Community
  • 1
  • 1
Henrik
  • 444
  • 4
  • 14