Jquery load file and test for hidden content - callback not helpiing

Posted on 2013-05-28
Last Modified: 2013-06-03
I have been trying to load an external file into a div - no problem

have been testing to see if some content is hidden - no problem
function isHidden(){
    var $s = $('.scrollable');
    $s.wrapInner('<div />'); // wrap inner contents
    var hidden = $s.height() < $s.children('div').height();
   $s.children('div').replaceWith( $s.children('div').html() ); //unwrap
    return hidden;

have been trying to do it in same function so it will all happen in order with one onclick

No matter how I try it even callback it seems to have to finish the entire function before the file appears in the div so, obviously, the hidden content detection fails every time.

Is this possible to do. I want to load the file into a div and, if content exceeds div - indicate there is more available at the bottom of the div - scrollbars are fine on the browsers but iphone and ipad scroll fine bit i am trying to indicate there is "more'. I thought I could load the div then test the content for hidden true/false and if true then unhide the notice element at the bottom of the content div.

Any help appreciated
Question by:drdocb
  • 3
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39203108
Can you please post a link to your page

Author Comment

ID: 39203194
Here is a sample page I was using for simplicity sake.

one link fills the div (and should callback the isHidden function via the fill(isHidden) on click

the other just calls the isHidden function

I have tried multiple combinations without success

Here is the code also

<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>

<script src="jquery-1.10.0.min.js">

      height: 150px;
      width: 75%;
      border: 1px solid #ccc;
      color: #03F;
      overflow: scroll;
      position: relative;
      margin-right: auto;
      margin-left: auto;
      text-align: center;
<script language="javascript">

function fill(callback)

function isHidden(){
    var $s = $('.scrollable');
    $s.wrapInner('<div />'); // wrap inner contents
    var hidden = $s.height() < $s.children('div').height();
    $s.children('div').replaceWith( $s.children('div').html() ); //unwrap
      return hidden;



<div class="scrollable" style="overflow:hidden;">
    test testtest testtest testtest<br />
    testtest testtest testtest testtest<br />
    testtest testtest testtest testtest<br />
      testtest testtest testtest testtest<br />
        testtest testtest testtest testtest<br />
    testtest test TOST
<p><a href="#" onClick="fill(isHidden)">Fill Div</a></p>
<p><a href="#" onClick="alert(isHidden())">check if your text is hidden</a></p>

Accepted Solution

drdocb earned 0 total points
ID: 39205778
Figured it out myself needed to open the callback function and include the callback code within it. Here is a portion of the modified call from a test page
function flow()
   $(document).ready(function() {
    var $s = $('.scrollable');
    $s.wrapInner('<div />'); // wrap inner contents
    var hidden = $s.height() < $s.children('div').height();
          $s.children('div').replaceWith( $s.children('div').html() );
                  if (hidden)
                    return true;

So I will close this question...

Author Closing Comment

ID: 39215649
Because I figured it out and it might help others as this is a hard concept to graso (or at least was for me and I have been programming for a LONG time)

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now