Split the word inside the <td> element

Is there a way to display the full text inside the <td> element? You can test it here:

$(document).ready(function(){
var users = [],
shuffled = [],
loadout = $("#loadout"),
insert_times = 30,
duration_time = 10000;
$("#roll").click(function(){
users = [];
//var lines = $('textarea').val().split('\n');
    var lines = "Excepteur sint occaecat cupidatat non proident \n adipiscing elit, sed do eiusmod tempor incididunt".split('\n')
if(lines.length < 2){
$("#msgbox").slideToggle(100);
setTimeout(function() {
  $("#msgbox").slideToggle(100);
}, 3000);
return false;
}
for(var i = 0;i < lines.length;i++){
if(lines[i].length > 0){
users.push(lines[i]);
}
}
$("#roll").attr("disabled",true);
var scrollsize = 0,
diff = 0;
$(loadout).html("");
$("#log").html("");
loadout.css("left","100%");
if(users.length < 10){
insert_times = 20;
duration_time = 5000;
}else{
insert_times = 10;
duration_time = 10000;
}
for(var times = 0; times < insert_times;times++){
shuffled = users;
shuffled.shuffle();
for(var i = 0;i < users.length;i++){
loadout.append('<td><div class="roller"><div>'+shuffled[i]+'</div></div></td>');
scrollsize = scrollsize + 192;
}
}


diff = Math.round(scrollsize /2);
diff = randomEx(diff - 300,diff + 300);
$( "#loadout" ).animate({
left: "-="+diff
},  duration_time, function() {
$("#roll").attr("disabled",false);
$('#loadout').children('td').each(function () {
var center = window.innerWidth / 2;
if($(this).offset().left < center && $(this).offset().left + 185 > center){
var text = $(this).children().text();
$("#log").append("THE WINNER IS<br/> <span class=\"badge\">"+text+"</span>");

}

});
});
});
Array.prototype.shuffle = function(){
var counter = this.length, temp, index;
while (counter > 0) {
index = (Math.random() * counter--) | 0;
temp = this[counter];
this[counter] = this[index];
this[index] = temp;
}
}
function randomEx(min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
});
.topbox{

background:white;
padding-bottom:40px;
    
}

.rollbox{
    width:100%;
height:200px;
background:white;
border:1px solid #eb3b5a;
    border-radius: 5px;
overflow-x:auto;
overflow:hidden;
position:relative;
padding:0;
}
.rollbox > table{
    background-color: yellow;
width:auto;
height:200px;
margin:0;
padding:0;

}
#loadout{
position:absolute;
top:10px;
left:5px;
z-index:1;
background:#121619;
}

.roller {
    border-right:1px solid white;
position:relative;
display: block;
height:100%;
text-align:center;
    color:white;
line-height:180px;
font-size:0.8em;
font-weight:bold;
font-family:sans-serif;
}
.roller div{
display:block;
height:50px;
line-height:50px;
position:absolute;
bottom:0;
width:100%;
left:0;

}

.badge{
padding-top:5px;
text-shadow:1px 1px 1px black;
margin-bottom:20px;
}
.line{
width:2px;
height:198px;
top:1px;
left:50%;
position:absolute;
background:#eb3b5a;
opacity:0.6;
z-index:2;

}

.roller{
height:180px;

width:180px;
margin-right:10px;

}
tr,table,td{
margin:0;
padding:0;
}

td:nth-child(even) .roller{

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="modal-content">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">×</span>
      </button>
   </div>
   <div class="modal-body">
      <div class="container">
         <div class="row topbox">
            <div class="col-md-12 col-md-offset-3 rollbox">
               <div class="line"></div>
               <table>
                  <tbody>
                     <tr id="loadout" style="left: -11248px;">
                        <td>
                           <div class="roller">
                              <img width="110" src="">
                              <div style="background-color:red;">
                              </div>
                           </div>
                        </td>

                     </tr>
                  </tbody>
               </table>
            </div>
         </div>
         <div class="row">
            <div class="col-md-6 col-md-offset-3">
               <div id="msgbox" class="alert alert-warning" style="margin-top:20px;display:none;">You need to add at least 2 lines!</div>
            </div>
         </div>
      </div>
   </div>

</div>
<button id="roll" class="btn btn-success form-control">Roll</button>

The content is as follows:

Excepteur sint occaecat cupidatat non proident 

As well as :

adipiscing elit, sed do eiusmod tempor incididunt

I attempted using

<p style="word-break: break-word;"></p>
, but sadly it didn't work in breaking the text.

Here's where the black boxes are created:

loadout.append('<td><div class="roller"><div>'+shuffled[i]+'</div></div></td>');

Answer №1

A few CSS updates have been made to your code. The changes include replacing line-height:50px with line-height:normal and adding word-break: break-word to the .roller div css. Give this a try as it should resolve the issue. Thank you!

.roller div{
    display:block;
    height:50px;
    line-height:normal;
    position:absolute;
    bottom:0;
    width:100%;
    left:0;
    word-break: break-word;
}

$(document).ready(function(){
var users = [],
shuffled = [],
loadout = $("#loadout"),
insert_times = 30,
duration_time = 10000;
$("#roll").click(function(){
users = [];
//var lines = $('textarea').val().split('\n');
    var lines = "Excepteur sint occaecat cupidatat non proident \n adipiscing elit, sed do eiusmod tempor incididunt".split('\n')
if(lines.length < 2){
$("#msgbox").slideToggle(100);
setTimeout(function() {
  $("#msgbox").slideToggle(100);
}, 3000);
return false;
}
for(var i = 0;i < lines.length;i++){
if(lines[i].length > 0){
users.push(lines[i]);
}
}
$("#roll").attr("disabled",true);
var scrollsize = 0,
diff = 0;
$(loadout).html("");
$("#log").html("");
loadout.css("left","100%");
if(users.length < 10){
insert_times = 20;
duration_time = 5000;
}else{
insert_times = 10;
duration_time = 10000;
}
for(var times = 0; times < insert_times;times++){
shuffled = users;
shuffled.shuffle();
for(var i = 0;i < users.length;i++){
loadout.append('<td><div class="roller"><div>'+shuffled[i]+'</div></div></td>');
scrollsize = scrollsize + 192;
}
}


diff = Math.round(scrollsize /2);
diff = randomEx(diff - 300,diff + 300);
$( "#loadout" ).animate({
left: "-="+diff
},  duration_time, function() {
$("#roll").attr("disabled",false);
$('#loadout').children('td').each(function () {
var center = window.innerWidth / 2;
if($(this).offset().left < center && $(this).offset().left + 185 > center){
var text = $(this).children().text();
$("#log").append("THE WINNER IS<br/> <span class=\"badge\">"+text+"</span>");

}

});
});
});
Array.prototype.shuffle = function(){
var counter = this.length, temp, index;
while (counter > 0) {
index = (Math.random() * counter--) | 0;
temp = this[counter];
this[counter] = this[index];
this[index] = temp;
}
}
function randomEx(min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
});
.topbox{
    
background:white;
padding-bottom:40px;
...

<tr,table,td{
margin:0;
padding:0;
}

td:nth-child(even) .roller{
background:url(http://re3ker.de/raffle/images/blue.jpg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
...

</div>
<button id="roll" class="btn btn-success form-control">Roll</button>

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

Difficulty with info window within a for loop

I am currently working on implementing multiple info windows for markers. I found an example on Stack Overflow that I am trying to follow. Despite not encountering any errors in the console, the info windows do not appear as expected when clicking on the m ...

Can you explain the significance of the 'X-Bandwidth-Est 3' error message that states, "Refused to get unsafe header"?

I'm currently facing an issue with all the websites I am working on where I keep encountering the following error: Refused to get unsafe header "X-Bandwidth-Est 3" in base.js. This error seems to be related to a YouTube file named base.js, but after ...

My website's logo is not appearing on the navigation bar in the HTML code

Hi there! I recently tried adding a logo to my navigation bar in an HTML file, but for some reason, the logo doesn't appear when I run the file. I'm currently learning web development through a course on Coursera, and I am quite new to programmin ...

The behavior of having two submit buttons within the $document.ready(function) in Jquery

In my code, I have implemented the behavior of two buttons, button1 and button2, within a $(document).ready(function). Whenever either button is clicked, an alert() function should be triggered. However, it seems that only button2 is functioning properly w ...

Chrome's new native lazy-loading feature

Recently, Chrome introduced support for the loading attribute, but I am experiencing issues with it. The image is loading even when it's not in the viewport. Here is my network info in DevTools User-agent: Chrome/75.0.3770.80 I have enabled la ...

My customized portfolio incorporates Bootstrap 4 and integrates a modal for collecting feedback. I am looking for a way to gather visitor feedback directly into a Google Sheet without relying on Google Forms

click here to view the image I am seeking feedback on my bootstrap modal from visitors. This portfolio is hosted in HTML and I am looking for a way to gather feedback without using a database, possibly through Google Sheets. ...

What sets apart binding attributes with [attr.attributeName] and [attributeName] in Angular 2?

Back when I used to bind attributes, my approach was like this: For instance: <input type="number" [max]="variableName"> Another example: <select [(ngModel)]="selectedItem"> <option *ngFor="let item of ...

Multer is set up to save only a single file from the req.files object into the

I am in the process of developing a straightforward webpage that includes a form for uploading images and other data to a SQL Server database using Node.js, Express, Sequelize for database connectivity, and Multer for handling file uploads. While I have so ...

Encountering a parsererror with $.ajax while processing JSON that includes a new Date() object

After fetching JSON from a MongoDB database, I serialize it and send it back to the JavaScript client using a $.ajax call. Here is an example of the $.ajax call: function server_request(URL, httpMethod, dataObject) { var output = ""; var typeofD ...

Extend and retract within a row of a table

I need help with modifying a dynamically generated table to meet specific requirements. The table currently looks like this. The task involves hiding all columns related to Category B, eliminating duplicate rows for Category A, and displaying entries from ...

What are the reasons behind Jquery's decreased speed performance in Internet Explorer?

My ASP.NET page is quite intricate and heavily depends on jQuery for manipulating the DOM without using AJAX. Interestingly, I've observed that the page performs better in Mozilla browsers like Firefox compared to Internet Explorer 7 or 8. Could it b ...

Is there a way to make the CSS3 border-image compatible with all the latest browsers, including IE 9+, Chrome, and Firefox?

Is there a way to implement border-image for a dynamically scaling CSS container across all modern browsers using a .js framework? If not, what would be a suitable alternative? To visualize the desired effect, check out: ...

What is the best way to call upon a necessary module from various files?

When working with Node.js, I am using Socket.io in my main.js file like this: const io = require('socket.io')(http); Additionally, I have a separate "sub" file called api.js where I delegate some of my business logic. To include this file, I us ...

Deleting a row from a Material UI table: Step-by-step guide

I'm currently working on a CRUD table using React and Material-UI. I have successfully fetched data from an API and displayed it in a table, but now I am facing a challenge with deleting a row. As this is my first project in React, I am seeking guidan ...

Mastering the Art of Trimming with Jquery

function DisplayDataForEdit(id) { $("#editContainer").slideDown("medium"); var parentId ='item'+ id; var colIndex = 0; var $row = $("#" + parentId).parent().parent(); $row.find('td').each(f ...

Is React State with JSON Object Losing Updates?

Encountering a strange issue here. At the start of my program, I load various values into a JSON object stored as a User State Object in a Postgres table. Although the object is quite large, I'll provide an example below. const [person, setPerson] = u ...

Drag near the bottom of a droppable DIV to scroll inside

Within a scrollable div, I have multiple draggable divs. However, when I drag them into another scrollable div (the droppable zone), only the page scrolls and not the droppable div itself. How can I make it so that only the droppable div scrolls while drag ...

The function send_filer either returns None or finishes execution without encountering a return statement

I am currently developing an application where users can download a plot.png and a file.csv, but the send_files function isn't working as expected. Below is my Python code: app = Flask(__name__) app.USE_X_SENDFILE = True @app.route('/', met ...

Tips for positioning ngb-timepicker in a column with perfect alignment

I am currently working on a time picker component in Angular 8, using bootstrap 4. I have been trying to center the ngb-timepicker within a col-12 inside this specific component. <div class="row pickerContainer"> <div class="col-12 pickerCente ...