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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:10:29+00:00 2026-06-16T21:10:29+00:00

I have a really nice little function that reduces the text size inside some

  • 0

I have a really nice little function that reduces the text size inside some div’s when they are displayed on the screen if they start overflowing.

$(function(){
    $('div.Body').each(function (index) {
        if ($('div.Body')[index].scrollHeight > 150) {
            $('div.Body')[index].style.fontSize = 'small';
            if ($('div.Body')[index].scrollHeight > 150) {
                $('div.Body')[index].style.fontSize = 'x-small';
                if ($('div.Body')[index].scrollHeight > 150) {
                    $('div.Body')[index].style.fontSize = 'xx-small';
                }
            }
        }
    });
})

I wanted to use the same/similar function to do the same while the users are typing the text into a textArea when they are submitting the text, but the textArea doesn’t seem to have a function for scrollHeight:

$(function() {
    window.status = $('.TextAreaClass').scrollHeight;
});

This function just returns undefined.

How can I accomplish this in a textArea?

  • 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-16T21:10:30+00:00Added an answer on June 16, 2026 at 9:10 pm

    scrollHeight is a native javascript method, not a jQuery one so you will need to do the following to get the scrollHeight of the textarea:

    window.status = $('.TextAreaClass')[0].scrollHeight;
    

    Note the [0] which returns the first element in the jQuery object, which is the native DOM element. Also, you should really be caching the selected element in your current code to make it perform better. Try this:

    $('div.Body').each(function (index) {
        var div = $('div.Body')[index];
        if (div.scrollHeight > 150) {
            div.style.fontSize = 'small';
            if (div.scrollHeight > 150) {
                div.style.fontSize = 'x-small';
                if (div.scrollHeight > 150) {
                    div.style.fontSize = 'xx-small';
                }
            }
        }
    });
    

    Finally, the logic of that code seems flawed, as all the conditions are checking > 150?

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

Sidebar

Related Questions

I have some really nice Python code to do what I need to do.
Suppose I have a SQL Query that isn't really nice. The SQL Query has
It's a small thing, really: I have this function that converts dict objects to
I'm getting some behavior from the Text constructors that don't really make any sense.
i have a really nice style for my tables. { sorry links no more
The linux kernel (and various other projects including git) have very nice makefiles that
I have a curious little problem. I have a service that needs to create
I Have a display that needs to be a little more dynamic than what
I have a nice little threading problem with a library I use to generate
I have a little sample application I was working on trying to get some

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.