Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:13:31+00:00 2026-06-12T13:13:31+00:00

In jQuery, I can very easily get the current computed height for an element

  • 0

In jQuery, I can very easily get the current computed height for an element that includes padding, border, and optionally margin by using outerHeight()…

// returns height of element + border + padding + margin
$('.my-element').outerHeight(true);

How would I do this in YUI? I’m currently using version 2.8.1.

Similar to this question, I can always do getComputedStyle() for height, border, padding, and margin, but that is a lot of manual labor which includes parsing the return values and grabbing the correct values that are needed and doing the math myself.

Isn’t there some equivalent function to jQuery’s outerHeight() in YUI that does all of this for me?

Solution

I ended up writing my own solution since I couldn’t find a jQuery outerheight() equivalent. I’ve posted the solution as an answer here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:13:32+00:00Added an answer on June 12, 2026 at 1:13 pm

    I ended up writing my own little utility function for this:

    /**
     * Calculates the outer height for the given DOM element, including the 
     * contributions of padding, border, and margin.
     * 
     * @param el - the element of which to calculate the outer height
     */
    function calculateElementOuterHeight(el) {
    
      var height = 0;
      var attributeHeight = 0;
      var attributes = [
          'height', 
          'border-top-width', 
          'border-bottom-width', 
          'padding-top', 
          'padding-bottom', 
          'margin-top', 
          'margin-bottom'
      ];
    
      for (var i = 0; i < attributes.length; i++) {
    
        // for most browsers, getStyle() will get us a value for the attribute 
        // that is parse-able into a number
        attributeHeight = parseInt(YAHOO.util.Dom.getStyle(el, attributes[i]), 10);
    
        // if the browser returns something that is not parse-able, like "auto", 
        // try getComputedStyle(); should get us what we need
        if (isNaN(attributeHeight)) {
          attributeHeight = parseInt(YAHOO.util.Dom.getComputedStyle(el, attributes[i]), 10);
        }
    
        // if we have an actual numeric value now, add it to the height, 
        // otherwise ignore it
        if (!isNaN(attributeHeight)) {
          height += attributeHeight;
        }
      }
    
      return isNaN(height) ? 0 : height;
    }
    

    This seems to work across all modern browsers. I’ve tested it in Chrome, Firefox (idk about 3.6, but the latest version works), Safari, Opera, & IE 7,8,9. Let me know what you guys think!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering if jquery can be used to manipulate my select html element
I've read that there is no way that JQuery can download a file directly,
Can JQuery/JavaScript read/get the file content on the client side, where the file is
With jquery i can't get links working AND animate the anchors' background both. It
Is it possible that some javascript or jquery can handle this: I have an
I like the jQuery DatePicker widget. It is very user friendly that when the
With the jquery.waypoints plugin you can easily create sticky elements. Its sticky elements demo
MOST of what the Flash is capable of jQuery can do that too... plus
JQuery - Can we capture both the p and div tags at a time
I found jquery can generate file tree structure based on existing folders and files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.