Ways to display a horizontal ellipsis at the end of a paragraph

Utilizing an HTML entity to display three dots (...) is my current method of indicating that there is more text available. While CSS (text-overflow: ellipsis;) offers alternatives, I am restricted in using CSS styles.

The problem lies in the fact that the ellipsis is appearing in the middle of the text - I require it to mimic the way manual three dots appear at the end of a text like,

Many people have sent language examples over the years...

This is what I currently see:

https://i.sstatic.net/F90aK.jpg

A horizontal ellipsis

<p><span>Sample Text:</span>Many people have sent language examples over the years, but we want more! We'd love to add more examples&#8230;</p>

Answer №1

ToolJS is a versatile JavaScript library that offers solutions to simplify your workflow.

One of its modules, the "Str" module, provides string manipulation functions, including the useful .truncate function.

Here's how you can use it:

Obtain the code from either the CDN or NPM, and follow the example below:

var Str = ToolJS.export("Str");
    
var myString = "Many people have sent language examples over the years, but we want more! We'd love to add more examples";
    
var newString = Str.truncate(myString, {
    limit: 40, // this is the number of characters you want to show in your string
    replacement: "..." // this is the replacement string
});
    
// Alternatively, you can use a shorthand implementation
    
var newString = Str.truncate(myString, 40, "...");
    
// To display it on your DOM
    
var DOM = ToolJS.export("DOM");
    
DOM.html("p", `<p><span>Sample Text:</span>${newString}</p>`);
<script src="https://unpkg.com/@redeakaa/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b4afafacaab380f1eef0eef1">[email protected]</a>/dist/umd/tooljs.min.js"></script>
<p><span>Sample Text:</span>Many people have sent language examples over the years, but we want more! We'd love to add more examples</p>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing a jQuery method in a PHP page that is loaded through AJAX

I am facing an issue on my page where I am using jquery/ajax to load a series of buttons into a div. This script loads buttons every time the user scrolls the page and each button should run a jquery function when clicked. The problem arises when I switche ...

Is there a way to stop a nested table from causing the parent table to expand?

This is where I'm demonstrating the issue: https://jsfiddle.net/ahnfcwdo/1/ Below is the structure of the table: table { max-width:100%; overflow: auto; } .table1 { border: 1px solid red; } .table2 { border: 1px solid blue; ...

Enhancing a bootstrap gallery with a zoom in effect

I need help creating a gallery using Bootstrap that resembles the style shown in this example: While everything is functional, I am facing an issue with aligning the pictures properly after adding a hover effect. I tried placing each picture in individual ...

Multiple web pages utilizing Angular app/widget

I have successfully built a chat application similar to Google Hangouts. However, I am facing a challenge with the angular app/widget running on other pages when URL's are changed, causing the app to either remain fixed or restart on the new web page. ...

Transforming external JavaScript and CSS scripts into HTML code

I am attempting to consolidate an external JS file and CSS file into a single HTML file by incorporating them internally in the HTML. While the CSS is functioning correctly with the style tag, the JS file seems to be causing some issues. What adjustments ...

The issue with Selenium chromedriver is that it is failing to execute the JavaScript scripts

Normally, the page loads like this: https://i.sstatic.net/GHSb4.png However, when opened with Chrome driver via Selenium in Python, it loads like this: https://i.sstatic.net/dO3Q2.png I have been trying to figure out how to execute JavaScript scripts on ...

Restrict the number of clicks allowed on a button

I am working on a project for my college where I need to restrict the number of times a button can be clicked to only 3 times. I have searched everywhere for code to achieve this and finally found some yesterday. The code is functioning partially as it giv ...

Struggling with aligning text in the center of a Navbar using Bootstrap4

I have implemented a Bootstrap navbar and I am facing difficulties in centering the content within it. <nav class="navbar navbar-light bg-light"> <div class="container"> <span class="navbar-brand mb-0 h1" ...

I am not familiar with this HTML element, it's a mystery to me

As I develop a data-recollection view in HTML, I've recognized the necessity of creating something similar to this: To elaborate, it's an image created hastily, with an input where users can enter data. When they click the "+" button, another in ...

Exporting MySQL data to MS Excel is functioning smoothly on the local environment, however, it is encountering difficulties when

<title>Orders Export</title> <body> <?php header('Content-Type: application/xls'); header('Content-Disposition: attachment; filename=download.xls'); $con = mysqli_connect('localhost','suresafe ...

Steps for identifying the file format of a document with JavaScript

Can someone assist me in determining a file type using JavaScript within the context of this HTML code? <div class="indi-download"> <div class="pull-left"> <h6 class="file-format">%file_display_name%</h6> </div> <div c ...

Initiate playing HTML video upon user click

My current situation is quite straightforward. I have an HTML video that plays when I click a div with the class ".play". $('.play').click(function() { $('.video').get(0).paused ? $('.video').get(0).play() : $('.vide ...

Tips for altering text size within Angular Material form fields with floating placeholder

Looking to customize the font size of the placeholder text in an Angular Material form field? You can set two different font sizes: one for when the placeholder is normal and one for when it floats. Here's how you can achieve this: <mat-form-fiel ...

Instead of displaying the location attribute in an alert, populate it into a text area

I have a function that can retrieve my current location using longitude and latitude coordinates. However, I am looking to automatically fill a text area (Populate Here) with the results instead of displaying an alert. <!DOCTYPE html> <html> ...

Conceal elements on smaller screens using the Bootstrap 5 grid system

I'm facing a design issue with my layout - it looks perfect on larger screens but when viewed on mobile devices, the columns stack vertically instead of horizontally. Essentially, I want to hide the first and second last column on small screens and r ...

Is there a potential bug when using .fadeOut() within a hidden element?

After examining the code provided: <div class='hotel_photo_select'> Hello </div> <div class='itsHidden' style='display:none'> <div class='hotel_photo_select'> Hello </ ...

Enhancing the appearance of the Switcher by framing it with

I've been working with the component package https://www.npmjs.com/package/react-switch-selector to create a design similar to this https://i.stack.imgur.com/voHqm.png Although I have made some progress, I'm struggling to add a border outline. H ...

Combining a background image with a contrasting background color in email design

Is it possible to create an email template with a table that has an image as a background, but also includes a substitute background color for platforms that don't display the image by default? I've experimented with the code below: <table b ...

How can I modify the color of a div when a validation error occurs?

I have recently completed a contact form with validation using the constraint validation api. Although the files are functioning as intended, I am curious if there is a method to make the error boxes turn red when an error occurs and white (or hidden) when ...

Controlling the HTML5 <audio>/<source> attribute using JQuery

Trying to create a basic audio player using the HTML5 audio tag. Within the main <audio> element, there are 3 <source> elements linked to different audio tracks in various formats for compatibility. To trigger a track change, a simple button wi ...