concealing additional content within a DIV using ellipsis

Looking to conceal additional text within my DIV element with ellipsis (...) at the end

Currently using:

<div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box">
 this is text this is text this is text this is text
</div>

Result:
The content overflowing the DIV is hidden
However, I would like three dots ... to be added at the end when hiding occurs

Desired Output:
this is text this is text this is te...

Answer №1

Check out this solution that utilizes the text-overflow:ellipsis property:

http://jsfiddle.net/FXHA3/

.ellipsis {
    width:200px;
    height:2em;
    line-height:2em;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
}

Answer №2

The term you seek is ellipsis, which is used to indicate the omission of words in a sentence.

Here's an illustration showcasing its application:

http://www.example.com/ellipsis-example

Answer №3

One way to achieve this is by incorporating a straightforward javascript function, particularly with the assistance of jQuery:

jQuery('#box').html(jQuery('#box').html().substr(0,30) + '...');

With this approach, the initial 30 characters will be displayed alongside three dots for truncation.

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

Tips for streaming an mp3 file on the internet

Is there a way to play an MP3 on a webpage without allowing users to download it? ...

What is the best way to pass the "getjson" capability from one function to another in a seamless manner?

Currently, I am dealing with a situation where a getjson call is used to retrieve a large amount of data. However, I find myself constantly having to check if the data is null or not. Here is an example: if (data.Height == "") { $(&ap ...

Apply CSS styling to the shadow root

In my preact project, I am creating a Shadow DOM and injecting a style element into the Shadow root using the following code: import style from "./layout/main.css"; loader(window, defaultConfig, window.document.currentScript, (el, config) => ...

MongoDB issued an error notification stating: "The operation `disneys.insertOne()` has experienced a timeout after 10000 milliseconds."

I am currently in the process of developing a new API using MongoDB and Express, and I have come across the following issue: "Operation disneys.insertOne() buffering timed out after 10000ms." To test my API, I am using route.rest. However, I ...

Is it possible for the Jquery Accordion to retract on click?

Hello everyone, I've created an accordion drop-down feature that reveals content when the header of the DIV is clicked. Everything works fine, but I want the drop-down to collapse if the user clicks on the same header. I am new to JQUERY and have trie ...

Display the uploaded images from uploadify on the webpage

I am currently working on a PHP website that utilizes uploadify for users to upload portfolio images. While I have successfully implemented uploadify, I am now exploring the most effective way to display these uploaded images on the webpage without requir ...

Unable to view any output in the console while attempting to troubleshoot a login functionality

My current setup involves using Node.js with Express and Pug templates. I have encountered an issue with a login function that is not functioning as expected. In order to troubleshoot the problem, I attempted to log the credentials (email and password) to ...

showing a new jsp page following the previous one

I am currently working on a JSP project where I have incorporated two text fields in the first.jsp file and then retrieving those values in the second.jsp file. My goal is to display these text field values on the same page in the browser after clicking th ...

What is the best way to change the name of a property within an object

I need to update the names of properties in a nested object. { 0: {value: "can_view"}, 1: {value: "can_create"} } The desired output should be: { user_can: "can_view", user_view: "can_create" } ...

Customizing Your Keyboard Design with CSS

I need assistance in creating a compact and dynamic keyboard layout with characters only, but I have hit a roadblock. Here is the link to my current progress: http://jsfiddle.net/45zDd The design is almost complete, however, the second and third rows req ...

Is it possible to alter the value of a global variable within a function and switch its value based on a local variable?

Currently, I am facing an issue with changing the value of a global variable dynamically from a function. The variable has a global scope and is also present in the same function as a local variable. However, despite my efforts, I am unable to successful ...

Troubles with Express JS session handling

I've encountered a challenge with sessions in my Express app. After a successful login, the code should direct the user to the 'dashboard' page by default if no specific URL is requested. The login.js file sets req.session.user to a user i ...

Is there a way to extract data within xml tags with attributes using JavaScript/ Ionic without relying on DOM or ActiveXObject?

I am trying to extract specific information located between two tags, specifically <wsse:BinarySecurityToken> Here is an example: <wsse:BinarySecurityToken att1="abc" att2="cd3" att3="adfa">This is the text I am trying to extract!!!</wsse ...

Activating a jQuery function as you move an item across the screen

Exploring the world of jQuery, I am eager to incorporate its drag and drop feature into my project. As I drag an item, I wish to invoke a function without interrupting the dragging process. The goal is to seamlessly continue holding the item while the func ...

Using Mongoose to insert a JavaScript object directly into the database

Recently, I've been working on POSTing a JS object through AJAX to the nodejs backend. My goal is to seamlessly insert this js object into my mongoose db without having to manually map each key to the schema. This is what I have currently (a bit clun ...

Issue with Ajax validation in Yii2 framework hasn't been resolved

I am trying to implement ajax validation for a unique field, but it's not working as expected. The validation works fine in my UserController, but for some reason, it's not functioning properly in my SiteController. Could someone please assist m ...

Combining 2 divs harmoniously

I have a set of HTML div elements that are styled using the following CSS: div{ width:250px; height:250px; display:inline-block; border-radius: 10px; margin:10px; background:#2E2922; vertical-align:top; } In my HTML, these div ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

Having trouble with the babel-loader and its version compatibility, as well as not finding the babel-loader folder in the node_modules directory when

Here are the steps I've taken: I cloned the project from Github. Ran the command 'yarn' to start the project. Encountered an error after running the command 'yarn start'. Even after following the steps provided in the e ...

Eliminate any repeated elements within the nested arrays found within an array of objects

Looking for a way to eliminate duplicates in this array structure. While mapping over arr, the values from each nested array within the objects are retrieved. However, I want to address and filter out any duplicate values. Current Result: bye hello hello ...