Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the 'height' of the screen using jquery [duplicate]

I want to set something in the middle of the screen

thanks

like image 415
zjm1126 Avatar asked Mar 09 '10 07:03

zjm1126


People also ask

How does jQuery calculate window height?

height() method is recommended when an element's height needs to be used in a mathematical calculation. This method is also able to find the height of the window and document. $( document ). height();

What is $( document height ()?

$(document). height() returns an unit-less pixel value of the height of the document being rendered. However, if the actual document's body height is less than the viewport height then it will return the viewport height instead.

How do you find the height of a dom?

Use offsetWidth & offsetHeight properties of the DOM element to get its the width and height.

What is jQuery height?

In jQuery, height method is used to get the height of any element in HTML. The height method sets and returns the height of the HTML elements. Method 1: The height() method returns the first matched element's height, But the height(value) method sets all matched elements height.


2 Answers

$(window).height();   // returns height of browser viewport $(document).height(); // returns height of HTML document 

As documented here: http://api.jquery.com/height/

like image 87
Dustin Laine Avatar answered Sep 22 '22 13:09

Dustin Laine


use with responsive website (view in mobile or ipad)

jQuery(window).height();   // return height of browser viewport jQuery(window).width();    // return width of browser viewport 

rarely use

jQuery(document).height(); // return height of HTML document jQuery(document).width();  // return width of HTML document 
like image 43
Piseth Sok Avatar answered Sep 22 '22 13:09

Piseth Sok