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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:46:24+00:00 2026-06-02T12:46:24+00:00

I’m currently using the css property ellipsis to add an ellipsis to the end

  • 0

I’m currently using the css property ellipsis to add an ellipsis to the end of my line. However, I also want to display the number of words after the ellipsis. For instance

.names {
    border: 1px solid #000000;
    white-space: nowrap;
    width: X;
    overflow: hidden;
    text-overflow: ellipsis;
}

<div class="names">Tim, Tom, Mary, Bob, Sam, John</div>

Shows

Tim, Tom, Mary, …

But, in this case I would want to show that the ellipsis represents 3 other names.

Tim, Tom, Mary, … and 3 others

What’s the minimal way to do this, either in javascript or with css. I’m using a webview in an iOS app and this will have to get calculated on every row item in a table so I would need to have a very lightweight js function.

  • 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-02T12:46:25+00:00Added an answer on June 2, 2026 at 12:46 pm

    I probably need a lot more rigid requirements in order to give you a better / more robust code for this. But I assume something like this is what you were looking for.

    http://jsfiddle.net/Xf47e/3/

    I don’t know how you are currently dealing with your code issues but I’d be surprised if you haven’t faced the issue of H… aka a half cut word already as well as many other problems that arise with the fact that character widths are most likely not constant with whatever font you are using.

    var names;
    $(document).ready(function() {
      names = $('p.test').text().split(',');
      for (i = 0; i < names.length; i++) {
        if (i < names.length - 1)
          $('p.test2').append(names[i] + ',');
        else
          $('p.test2').append(names[i]);
        console.log(i + " " + $('p.test2').width());
        if ($('p.test2').width() > 100) {
          break;
        }
      }
      $('p.test2').append(' ... and ' + (names.length - i + 1) + ' others.');
    });
    p.test {
      width: 100px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    p.test2 {
      float: left;
    }
    <!DOCTYPE html>
    <html>
    
    <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>
    
    <body>
      <div>
        <p class="test">Tom, Bob, Harry, Dick, John, James, Smith, Paul</p>
        <p class="test2"></p>
      </div>
    </body>
    
    </html>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
i want to parse a xhtml file and display in UITableView. what is the
I am using parse_ini_file to read the contents of a file however it is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words

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.