![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is to be done when text overflows the containing element with JavaScript?
Use the textOverflow property to counter the text overflow issue. Add ellipses if the text overflows the containing element.
Example
You can try to run the following code to learn what is to be done when text overflows the containing element with JavaScript −
<!DOCTYPE html> <html> <head> <style> #myID { border: 2px solid blue; background-color: gray; overflow: hidden; text-overflow: visible; width: 200px; white-space: nowrap; } </style> </head> <body> <button onclick = "display()"> Click </button> <div id = "myID"> This is Demo Text! This is Demo Text! This is Demo Text!<br> This is Demo Text! This is Demo Text! This is Demo Text!<br> This is Demo Text! This is Demo Text! This is Demo Text!<br> This is Demo Text! This is Demo Text! This is Demo Text!<br> </div> <script> function display() { document.getElementById("myID").style.textOverflow = "ellipsis"; } </script> </body> </html>
Advertisements