How to use outerHeight() Method in JQuery

In this article, I will explain use of outerHeight() Method in JQuery.
  • 2433

JQuery CSS outerHeight() Method

  • outerHeight([margin]) method gets the outer height for the first matched element.
  • outerHeight([margin]) method return height with include the border and padding.
  • outerHeight([margin]) method works for both visible and hidden elements.

Syntax

$(selector).outerHeight([margin])

Example

The following example shows how to outerHeight() method in jquery.

<html>

<head>

<title>the title</title>

   <script type="text/javascript"

   src="JScript.js"></script>

   <script type="text/javascript" language="javascript">

       $(document).ready(function () {

           $("div").click(function () {

               var color = $(this).css("background-color");

               var height = $(this).outerHeight();

               $("#result").html("Outer Height is <span>" +

                         height + "</span>.");

               $("#result").css({ 'color': color,

                   'background-color': 'black'

               });

               $("#result").height(height);

           });

 

       });

   </script>

   <style>

      #div1{ margin:10px;padding:12px;

             border:2px solid #666;

             width:60px;}

      #div2 { margin:15px;padding:5px;

              border:5px solid #666;

              width:60px;}

      #div3 { margin:20px;padding:4px;

              border:4px solid #666;

              width:60px;}

      #div4 { margin:5px;padding:3px;

              border:3px solid #666;

              width:60px;}

  </style>

</head>

<body>

      <h2>outerheight() Method Exapmle</h2>

   <p>Click on any square for get outer height:</p>

   <span id="result"> </span>

   <div id="div1" style="background-color:red;"></div>

   <div id="div2" style="background-color:Maroon;"></div>

   <div id="div3" style="background-color:Green;"></div>

   <div id="div4" style="background-color:Fuchsia;"></div>

</body>

</html>

 

Output


outer height.jpg

Further Readings

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.