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

334
Visualizações
How to do a line break in HTML with external Javascript file?

Making a website for my Javascript class which tells the user information about their browser and such. I have the technical part down, but line breaks aren't working for some reason and it's making formatting a headache. For example, here is a function that pretty much tells the user's screen resolution and puts it into the empty output div in the HTML

function screenResolution() {
    clearBox();
    document.getElementById('heading').textContent = "Screen Resolution";
    document.getElementById('output').textContent = "Width: " + screen.width + "Height: " + screen.height;
}

I'm wanting to put a line break inbetween Width: xyz and Height: xyz so it looks like

Width: 1920

Height: 1080

but using \n or <br> both don't seem to be working. It'll just put the tags in like they're strings so it'll look like

Width: 1920<\br>Height:1080

Any help?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should be able to use innerHTML property instead of textContent:

document.getElementById('output').innerHTML = "Width: " + screen.width + "<br>Height: " + screen.height;

This is assuming that output is not a text field or textare (i.e. div, td, etc)

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