Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
I have an issue with breaking lines in javascript html

I have an issue with breaking line in javascript. It doen't make a break line in html page, how can i fix this?

Doesn't makes brakes

let currentDate;

var botHp;
var playerHp;

const postlog = function(message) {
  document.querySelector(".gamelogchat").textContent += message;
};

document.querySelector(".cardbutton").addEventListener("click", function() {
  console.log("click");
  currentDate = new Date();
  let Time =
    currentDate.getHours() +
    ":" +
    currentDate.getMinutes() +
    ":" +
    currentDate.getSeconds();

  postlog(Time + "\r\n");
});
<div class="gamelog">
  <h1 class="gamename">Game</h1>
  <p class="gamelogname">Game log</p>

  <div class="gamelogbox">
    <p class="gamelogchat"></p>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

This should fix the problem:

let currentDate;

var botHp;
var playerHp;

const postlog = function(message) {
  document.querySelector(".gamelogchat").innerHTML += message;
};

document.querySelector(".cardbutton").addEventListener("click", function() {
  console.log("click");
  currentDate = new Date();
  let Time =
    currentDate.getHours() +
    ":" +
    currentDate.getMinutes() +
    ":" +
    currentDate.getSeconds();

  postlog(Time + "<br>");//\r\n
});
<div class="gamelog">
  <h1 class="gamename">Game</h1>
  <p class="gamelogname">Game log</p>

  <button class="cardbutton">Test Button</button>
  <div class="gamelogbox">
    <p class="gamelogchat"></p>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

Try to change on

document.querySelector(".gamelogchat").innerHTML += message + "<br />";

Mb, it's better to understand with demo: https://codesandbox.io/s/trusting-phoebe-9zl3h?file=/src/index.js

about 4 years ago · Juan Pablo Isaza Report

0

Just use this:

let currentDate;  
var botHp;  
var playerHp;  

const postlog=function(message)
{
  document.querySelector('.gamelogchat').textContent+=message;
};

document.querySelector('.cardbutton').addEventListener('click',function()
{
  console.log('click');
  currentDate=new Date();
  let Time=currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds();    
  postlog(Time+'<br/>');
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!