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

89
Visualizações
vs code wrap multiple line in quote

I am new to vscode and and hardly get bothered by one thing.

var template = "<div>
                  <input type="text" class="input">  
                  <input type="text" class="input"> 
                  <input type="text" class="input">  
                  <input type="text" class="input"> 
                  <input type="text" class="input"> 
                </div> "

I have no clue why vscode is not wrapping all those line in quote. It just throws a syntax error. It reads when they aligned in one line but when I break the line to make it look good, the code is not working. Any idea?

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

0

You can do like this:

var template = `
  <div>
    <input type="text" class="input">  
    <input type="text" class="input"> 
    <input type="text" class="input">  
    <input type="text" class="input"> 
    <input type="text" class="input"> 
  </div>
`;
                    
document.body.innerHTML = template;

If you aren't familiar with template strings here is the MDN documentation.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try this way. Just use single quotes to surround the variable string, and use backslashes to change lines.

var template = '<div>\
                  <input type="text" class="input"> \
                  <input type="text" class="input"> \
                  <input type="text" class="input"> \
                  <input type="text" class="input"> \
                  <input type="text" class="input"> \
                </div>';
                
document.body.innerHTML = template;

about 4 years ago · Juan Pablo Isaza Relatório

0

It fails because of multiple reasons:

  1. You use double-quotes both to open and closing the variable aswell as the attributes. The opening double-quote of the first attribute already closes the variable therefor.
  2. A JS variable is not allowed to have linebreaks.
  3. you do not close the variable with a semicolon or comma (in case more variables follow)

The only way you can fix it is like in the example below. You have to open and close the variable and use a + to continue the variable in the next line:

var template = '<div>' +
                 '<input type="text" class="input">' +
                 '<input type="text" class="input">' +
                 '<input type="text" class="input">' +
                 '<input type="text" class="input">' +
                 '<input type="text" class="input">' +
               '</div>';
            
document.body.innerHTML = template;

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