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

143
Views
Set innerHTML of DOM with template tag

I am currently working on a Vue project, and I am trying to set the innerHTML of a HTML element with a template tag. For example:

let divElem = document.getElementById('divElem')
let innerHTMLContent = `<template><div>test</div></template>`
divElem.innerHTML = innerHTMLContent

However, the content of the innerHTMLContent does not get rendered. Instead, it shows #documentfragment below the template tag when I do the Inspect -> Elements. I strongly suspect is the template tag that is causing the issue.

Is there any advice on how I can get the innerHTML to render the template tag?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You ran into the DocumentFragment Pitfall here. You are right that this has to do with the template.

You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template#avoiding_documentfragment_pitfall

as <template> is being used to render content later on with e.g. Javascript this wont work as changes are expected after adding the template to the DOM, probably not with it.

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