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 7527939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:14:19+00:00 2026-05-30T04:14:19+00:00

Some text has been retrieved via an AJAX call and needs to be inserted

  • 0

Some text has been retrieved via an AJAX call and needs to be inserted into the DOM:

$("#someInsertionPoint").append(someHtml);

someHtml might be small, so as to create a resulting height for #someInsertionPoint of 50px. Then again, there might be so much text that #someInsertionPoint ends up with a height of 300px or more in order to contain all of the text.

In cases where someHtml is lengthy, the specifications call for a truncated version of the text to be shown (with trailing ellipsis), followed by a “more…” link which when clicked, increases the height of #someInsertionPoint, in an animated way, so as to accommodate the full text.

Everything seems straight-forward with one exception: How do I determine what the height of #someInsertionPoint will be when the full text is inserted? Recall that this value will be used as an end-point for the animated height change that occurs when the user clicks the “more…” link. Some posts on StackOverflow.com indicate that the height can’t be pre-calculated; It can only be retrieved after the insertion of text is complete. This leads me to believe that my approach should be as follows:

(1) Set the visibility of someInsertionPoint to “hidden”.

(2) Insert the full text and cache the height of someInsertionPoint in a variable.

(3) Truncate the inserted text and add the ellipsis. Set the height of #someInsertionPoint to 50px.

(4) Make someInsertionPoint visible to show the truncated text at a height of 50px.

(5) When the “more…” link is clicked, the truncated text can be replaced with the full text and I can animate the height to its ideal size using the height that I cached in #2.

Is there a better way?

Thanks.

  • 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-05-30T04:14:22+00:00Added an answer on May 30, 2026 at 4:14 am

    I think you create a problem as it is normally no problem. It is a design flaw. Simply don’t use fixed heights. If you want to autosize something use a min-height and let the content do the resizing stuff. That’s the easy way. Otherwise when you want to use fixed heights you can use a two divs (one with a fixed height) and measure the ‘ajax’ height after you insert it (it must be visible to calculate heights).

    For example:

    <div id="fixed" style="height:200px;overflow:hidden">
     <div id="loader">
    </div>
    
    $('#loader').html('your content');
    alert($('#loader').outerHeight());
    

    When you try this example the #fixed div will not resize when loading net content. After inserting you can measure the height and adjust the parent div #fixed if you want.

    Hopes it helps

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

Sidebar

Related Questions

Here's one usecase that has been baffling me. When I select some text and
I have some text that has HTML hyper-links in it. I want to remove
Let's say I have some original text: here is some text that has a
I have a JeditorPane which has some text in HTML format. When I execute
I have a Project model and it has some text attributes, one is summary.
I have model Article it has field title with some text that may contain
I have a custom UITableViewCell which has an image & and some text. When
I just want a simple SVG image that has some arbitrary text on an
I have a simple WPF (XAML) file that has some animated shapes and text.
I've a text file with 2 million lines. Each line has some transaction information.

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.