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

186
Visualizações
Is it possible to set the inner HTML of an element with a file using d3js?

I am trying to clean up some code that I am writing and I had a thought: Would it be possible to set the inner HTML of a component using d3js like the code below?

d3.select("body").append("div").html(d3.html("../components/modal.html"));

If this is possible, what is needed to make it work, because right now, this only puts a text field on the page that says [object Promise]

Is this only wishful thinking?

EDIT: I am using Bootstrap 5 to implement my modal

UPDATE:
As I described in a comment below, I took the code from @SmokeyShakers answer---

d3.html("../components/modal.html").then((data) => {
      d3.select("body").append("div").html(data)
    })

---and replaced the first .html(...) with .text(...) as so:

d3.text("../components/modal.html").then((data) => {
      d3.select("body").append("div").html(data)
    })

This made it so that the modal would actually render, but the buttons and other functionalities I had built into the modal wouldn't work. And for additional information, my modal buttons did not have an onclick="..." attribute in the inline HTML, but it was added using

d3.select('#my-modal-submit').on('click', ()=>{...})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this out. d3.html is a fetch, so I think you need to go inside out:

    d3.html("../components/modal.html").then((data) => {
      d3.select("body").append("div").html(data)
    })
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