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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:14+00:00 2026-05-26T03:00:14+00:00

I have some elements on my page which have the CSS rules white-space ,

  • 0

I have some elements on my page which have the CSS rules white-space, overflow, text-overflow set, so that overflowing text is trimmed and an ellipsis is used.

div {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;

  border: 1px solid black;
  width: 150px;
  margin: 5px;
  padding: 5px;
  font-family: sans-serif;
}
<div>
  <span>Normal text</span>
</div>
<div>
  <span>Long text that will be trimmed text</span>
</div>

Is there any way I can use JavaScript to detect which elements’ contents are overflowing?

  • 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-26T03:00:14+00:00Added an answer on May 26, 2026 at 3:00 am

    Once upon a time I needed to do this, and the only cross-browser reliable solution I came across was hack job. I’m not the biggest fan of solutions like this, but it certainly produces the correct result time and time again.

    The idea is that you clone the element, remove any bounding width, and test if the cloned element is wider than the original. If so, you know it’s going to have been truncated.

    For example, using jQuery:

    var $element = $('#element-to-test');
    var $c = $element
               .clone()
               .css({display: 'inline', width: 'auto', visibility: 'hidden'})
               .appendTo('body');
    
    if( $c.width() > $element.width() ) {
        // text was truncated. 
        // do what you need to do
    }
    
    $c.remove();
    

    I made a jsFiddle to demonstrate this, http://jsfiddle.net/cgzW8/2/

    You could even create your own custom pseudo-selector for jQuery:

    $.expr[':'].truncated = function(obj) {
      var $this = $(obj);
      var $c = $this
                 .clone()
                 .css({display: 'inline', width: 'auto', visibility: 'hidden'})
                 .appendTo('body');
    
      var c_width = $c.width();
      $c.remove();
    
      if ( c_width > $this.width() )
        return true;
      else
        return false;
    };
    

    Then use it to find elements

    $truncated_elements = $('.my-selector:truncated');
    

    Demo: http://jsfiddle.net/cgzW8/293/

    Hopefully this helps, hacky as it is.

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

Sidebar

Related Questions

I have some elements on a page which are draggable. These same elements have
On extracting some html from a web page, I have some elements containing text
I have some page elements which are meant to appear in a two column
I have some the page elements split into separate visual blocks. I am currently
Please help! I have some form elements in a div on a page: <div
I have an XML page with some elements in various languages - Arabic, English,
I've copied some text nodes from the page (i.e., live DOM) and have stored
I have long known that you can load style rules into a page dynamically
Within an asp.net webform I have some jquery that controls the positioning of elements
I have some elements on the page. Here is example of one element: <div

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.