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

200
Visualizações
innerHTML assignment removes all (including the last) whitespace in a empty tag

I assign a string with html tags to a newly created div:

const wrapper = document.createElement('div')
wrapper.innerHTML = this.html

this.html looks like this (please note the whitespace in the span.b tag):

<span class="a"></span><span class="b" data-topicId="mark.001" data-type="R">
                    </span><span class="c"><span class="d">

After the innerHTML assignment I render the HTML with vue:

return {
    name: 'NormalizedContent',
    template: wrapper.outerHTML,
    [...]
}

up until the last wrapper.outerHTML I can see multiple (at least one) whitespace with console.log, after it is rendered, the whitespace is gone.

screenshot from the browser inspector

I want to keep at least one and I can't replace them programmatically e.g. with &nbsp;.

about 4 years ago · Juan Pablo Isaza
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