treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Changing something based on the browser window width

  • Hi all,
    I know there's a simple solution but I cant find it.
    How do I change the css of something if the browser window width is less than a certain number of pixels… using jquery.

    Thanks
    Rohan Merchant
  • Try this
    if( $(window).width() < 900 ) {
    console.log(\"Less\");
    }else {
    console.log(\"More\");
    }
  • Thanks
  • You might want to add this in case the browser is resized.
    // On Resize
    $(window).resize(function() {
    if( $(this).width() < 900 ) {
    console.log(\"Less\");
    }else {
    console.log(\"More\");
    }
    });