Summary of differences between height (), innerheight (), and outerheight () in jQuery, jqueryouterheight

Source: Internet
Author: User

Summary of differences between height (), innerheight (), and outerheight () in jQuery, jqueryouterheight

Suddenly we see outerheight () in the front-end jQuery code. The first thought is, what is this? Then I checked it carefully and found that there were many similar things.

In jQuery, there are three functions for retrieving the element height: height (), innerHeight (), and outerHeight ().

Correspondingly, there are also three functions for Retrieving Element width, which are width (), innerWidth (), and outerWidth ().

What are the differences between them? Take the box model as an example:

Height (): The height range is the height of the matched element;

Innerheight (): The height range is the height + padding of the matched element;

Outerheight (): The height range is the height of the matched element, height + padding + border;

Outerheight (true) the height range of the matched element is height + padding + border + margin;

    <div id="element" style="margin:5px; padding:10px; width:100px; height:100px; border:1px solid #000;"></div>    <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>    <script type="text/javascript">    var $ele = $("#element");    // height() = height(100) = 100    document.writeln($ele.height()); // 100    // innerHeight() = height(100) + padding(10*2)= 120     document.writeln($ele.innerHeight()); // 120    // outerHeight() = height(100) + padding(10*2) + border(1*2) = 122     document.writeln($ele.outerHeight()); // 122    // outerHeight(true) = height(100) + padding(10*2) + border(1*2) + margin(5*2) = 132     document.writeln($ele.outerHeight(true)); // 132    </script>

The same is true for the width in the horizontal direction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.