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

144
Visualizações
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 Respostas
Responde à pergunta

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 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