JavaScript jQuery get height of the contents in a container jquery height of div contents,jquery get iframe contents height,

I'm not even sure if this is possible but I want to get the height of the contents in a container. Let's assume I have

<div id="container" style="min-height:100vh">
    <div class="child">
      <p>Some text here</p>
    </div>
    <div class="another-child">
      <p>Some text here</p>
    </div>
</div>

How do I get the true height of the content of #container? Those inline heights are just as example to show parent height could be anything. I want to know how much the content are truly occupying. Again assuming that there could be an arbitrary number of child tags.

note in the example above the true height is the height of those paragraphs combined if they aren't inline.

Answer:1

Not sure if this can be done using single jQuery/javascript function . But this snippet can be useful

HTML

 // Added a common class to all child element of div#container
     <div id="container" style="min-height:100vh">
        <div class="child cc">
          <p>Some </br>text here</p>
        </div>
        <div class="another-child cc">
          <p>Some text here</p>
        </div>
    </div>

JS

// Loop through all child element using common class to get the total height
var cc = 0;
    $("#container > div.cc").each(function(){
        cc += $(this).outerHeight();
    });
$('#height').append('<p>'+ cc+'</p>' );

CSS

 p{
    margin:0px;
        }

Look here if you want to know why setting margin:0

JSFIDDLE

EDIT

Add an iterator to exclude inline elements. Also the .each is iterating on elements which has cc class. So you can made inline not to have cc class.

Here is a snippet of checking display type of the element before adding their height.

var cc = 0;
    $("#container > .cc").each(function(){
      var getDisplay = $(this).attr('dipslay') // Check the display attribute
       // Using ternary operator 
       getDisplay !=='inline'? (cc += $(this).outerHeight()) :0;
     });

UPDATED FIDDLE

Answer:2

Try using window.getComputedStyle(/* DOM element */).getPropertyValue("height")

console.log(window.getComputedStyle($("#container")[0]).getPropertyValue("height"))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<div id="container" style="min-height:100vh">
  <div class="child" style="height:100%">
    <div class="another-child">
      <p>Some text here</p>
    </div>
    <div class="another-child">
      <p>Some text here</p>
    </div>
  </div>
</div>
Answer:3

You can use the .height()-functions of jQuery:

$('#container').height();

Get the current computed height for the first element in the set of matched elements

Or

$('#container').innerHeight();

Get the current computed inner height (including padding but not border) for the first element in the set of matched elements

Or

$('#container').outerHeight();

Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin


Demo

Answer:4

Use the jQuery method $("selector").height(); This will return you how much your container is occupying.

Answer:5

I've been battling with this for hours now and read several threads on SO and other places, but have hit a dead end. I am trying to scrape a web page and one of the items I need is a text file that is ...

I've been battling with this for hours now and read several threads on SO and other places, but have hit a dead end. I am trying to scrape a web page and one of the items I need is a text file that is ...

  1. text file download
  2. downloading text file java
  3. downloading a text file from a website
  4. curl downloading text file
  5. android download text file
  6. pdf downloading as text file
  7. video downloading as text file
  8. content type for downloading text file

Good day fellow Stack-ers, I must ask your pardon if this question has been asked before or if it seems elementary (I am only a Javascript novice). I have been doing w3c js challenges lately: Write ...

Good day fellow Stack-ers, I must ask your pardon if this question has been asked before or if it seems elementary (I am only a Javascript novice). I have been doing w3c js challenges lately: Write ...

We are using the Taxonomy module for Sitecore: https://marketplace.sitecore.net/Modules/T/Taxonomy.aspx?sc_lang=en The module works fine 90% of the time. The only catch is that when in a taxonomy ...

We are using the Taxonomy module for Sitecore: https://marketplace.sitecore.net/Modules/T/Taxonomy.aspx?sc_lang=en The module works fine 90% of the time. The only catch is that when in a taxonomy ...

I have 3 pages, the 2 pages are WordPress pages and the other 1 is a custom page template with a form. The 2 pages are created using wp-job manager plugin. The 1st page has had a dropdown menu and ...

I have 3 pages, the 2 pages are WordPress pages and the other 1 is a custom page template with a form. The 2 pages are created using wp-job manager plugin. The 1st page has had a dropdown menu and ...

  1. value using vin
  2. value using cap rate
  3. @value using
  4. value using a sentence
  5. car value using vin
  6. set value using jquery
  7. p value using z score
  8. p value using excel
  9. set value using javascript
  10. p value using t score
  11. get value using jquery
  12. average value using integrals
  13. value scales using line
  14. select value using jquery
  15. car value using vin number
  16. p value using test statistic
  17. p value using t
  18. set value using document.getelementbyid
  19. place value using decimals
  20. expected value using cdf