Tuesday, 23 December 2014

jQuery Window Width – Browsers and Responsive Design

jQuery Window Width

jquery window width, you’ll need it if you’re working with Responsive Design and/or need to figure out the width of the browser Window? Are you using a responsive design layout and using viewport, but need a way to determine window width? jQuery width() and jQuery resize() can help.

Responsive Design

With so many devices able to access the internet, Responsive Design is becoming a necessity.   Smart phones, tablets, laptops, and desktop computers have different viewable areas. Viewport is the window size of the device. We’ll use jquery width and resize functions to determine the window width of the screen thus aiding us in our Responsive Design.
To determine the browser window width and if it gets resized we’ll use:
  • jquery width
  • jquery resize
  • window

jQuery Window Width Determined

jQuery .width() returns a numerical value only, i.e.325.  The value is in pixels.  However, .css(width) will return the number and units, i.e. 325px.   We want to use jQuery window width since we’ll test for numerical values later.

var wi = $(window).width(); // Stores the numerical value of the width into the variable "wi"

Window vs. Document vs. Screen

Why window width?  The window “holds” the document. Because the document is what gets loaded into the Window object we’ll use $(window).width().  I also use  jquery window width instead of screen width.  If someone doesn’t have their browser windowmaximized to full screen then it only makes sense to get the width of the window size they are using and not the screen.

$(window).width();   // This will return the width of browser viewport
$(document).width(); // This will return the width of HTML document
$(screen).width(); // This will return the width of the users screen
//Since the document is what gets loaded into the Window object, and the
//browser window may not be maximized to full screen we'll use $(window).width();

jQuery Window Resize

What happens if the window is resized?  Luckily jQuery has a function to test if an object gets resized.  The code below will show the window width when resized.

$(window).resize(function() {
        var wi = $(window).width();
        $("p.testp").text('Screen width is currently: ' + wi + 'px.');

jQuery Window Width

The code below will use jQuery window width to show the initial screen width, but not once it’s resized.

jQuery Window Width Determined Initially and When Resized

We’ll put it all together here.  We’ll use jQuery window width and resize as we did above.  I will provide the HTML to be manipulated further below.

jQuery Window Width HTML

Below is the HTML required. We use the jQuery / javascript code above to manipulate the HTML code below.


  1. Behance - Golpik

    I like your blog thanks for sharing about blog wow

  2. Thank you sir And keep it up More Post And Its A Awesome Web page sir Thank You So Much

  3. I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1...Please visit our wonderful and valuable website-

  4. I really enjoyed reading your blog, you have lots of great content.Please visit here:
    Gurgaon Packers And Movers is recognized as a business manager providing wide-ranging and differentiate service appearance as well as Relocation Shifting.Packers And Movers Gurgaon

  5. Excellent post! I must thank you for this informative read.Please Visit Our Webpage:
    In loading and unloading is done carefully by experienced workers. In addition, #PackersMovers unpacks the delivery at the target, very efficiently & with maximum care.

  6. Thanks for sharing useful information for us.I really enjoyed reading your blog, you have lots of great content.Please visit here:

  7. An excellent information provided thanks for all the informations i must say great efforts made by you.

  8. I really enjoyed reading your blog, you have lots of great content.Please visit here:
    Packers And Movers Patna Relocation, Main Office in Patna India, is a most important company relocation and home Shifting services association provided that relocation solutions to individuals and company houses.
    Packers And Movers Patna

  9. Thanks on your marvelous posting! I really enjoyed reading it, you’re a great author.Please visit here:http://packersmovershyderabadcity.in/
    Packers And Movers hyderabad
    based company provided that Movers And Packers Hyderabad Services for Office, Home, Local or domestic and commercial purposes.

  10. Great information on your site here. I love this post because we can get some useful information from your blog. I expect more post from you guys.
    Packers And Movers Bangalore

  11. Mother's Day is a celebration in regards to the mother of the family, and furthermore parenthood, maternal bonds, and the effect of mothers in the general population field. It is commended on various days in many parts of the world, most routinely in the seasons of February or normal of the week. It supplements near celebrations with respect to relatives, for instance, Father's Day and Siblings Day.

  12. Have Lovely and Beautiful Salwar Suit And Many More…
    We Have Some For You In Your Budget For more…
    Plz visit:- Ladies Suit

  13. The best collection of Happy Mothers Day 2017 Images, Photos, Pictures, Wallpapers, Mothers Day Quotes, Wishes, Messages, Greetings,
    Happy Mothers Day Poems & Sayings, Mothers Day Messages, SMS, Text Messages,
    fathers day images 2017
    fathers day wallpapers 2017
    fathers day pictures 2017
    fathers day cards 2017
    Happy fathers day images 2017
    fathers day quotes 2017
    fathers day wishes 2017
    fathers day messages 2017
    fathers day status 2017
    fathers day poems 2017
    Memorial Day wishes 2017
    Mothers Day WhatsApp Status & Facebook Status, DP Images,
    Mothers Day FB Profile Pics, FB Timeline Cover Photos etc.

  14. Our Collection is Best Designer Saree Lehenga, Gown ,Salwar Kameez etc...
    For more...
    Designer Kurti
    Wedding Dresss
    Punjabi Suit
    Diwali,Christmas,New year for Collection....
    Happy Diwali
    Merry Christmas
    Happy New Year

    Brindal Lehenga

  15. A movie is used for an entertainment of busy people.
    By seeing movie person experiences refreshment from their day to day life.
    For watching movie plz visit following site:-
    kingsman: the golden circle full movie download kickass torrent
    kingsman: the golden circle full movie the piratebay