SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2011
    0 Post(s)
    0 Thread(s)

    Getting the .height() of div populated from script

    Hello all,
    I have this situation where I have a bunch of divs that get populated mostly from templates. My data comes from many sources but I am only having trouble with the div (div3) that has data coming from a script. I am trying to get the height for this div but it seems that theJQuery .height() and the .css('height') get the values after the site has rendered (ready()) but NOT after the script data has returned, therefore I am getting a height of 0 even though there is data coming to populate my div3. The data comes from an external source so I have no control over it. Here is what the code looks like:

    HTML Code:
    <div class="div1">
    	...some content
    	<div class="div2">data comes from DB</div>
    	...some content
    	<div class="div3">data comes from script</div>
    <div class="div4">
    	..some content
    Any ideashow to get the height for div3? Thanks in advance.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Melbourne, AU
    17 Post(s)
    1 Thread(s)
    I would recommend you give your div3 element a minimum height that you can use then run an interval to detect when the height has changed and run your script accordingly, see the below example:

    Code JavaScript:
    var itv = setInterval(function() {
        // Check if the height is greater or less then the original value we set
        if ($('.div3').height() <> 500) {
            // Do something here...

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts