Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda