Home > UI/UX Development > jQuery > Calculate height and width of an element with respect to window/document height and width

Calculate height and width of an element with respect to window/document height and width

  1. Get height of window
    $(window).height(): Returns height of visible viewport/screen (does not include height of scrollable content)
  2. Get height of the page
    $(document).height(): Returns height of the length of the content/page (includes the height of the scrollable content)
  3. Get width of window
    $(window).width(): Returns width of visible viewport minus width of scrollbar (which is 17px for most of the browser except mobile versions and Edge)
  4. Get width of the page
    $(document).width(): Returns width of visible viewport minus width of scrollbar (which is 17px for most of the browser except mobile versions and Edge)

Good luck calculating height and width w.r.t. the screen or page.

This Article is TAGGED in , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">