Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!