Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda