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

253
Visualizações
How can i create a function that removes a div when I push a link?

I'm a beginner coder. Could someone help me make it so that when I press on an exit link the html that I injected before disappears?

const btnif = document.querySelector("#ytif");
const ifpss = document.querySelector(".ifpss");

btnif.addEventListener('click', () => {
  ifpss.innerHTML = `<div class="ytifrore"><div class="ytiframe"><div 
  id="closep"> &times;
  Fermer la page </div><iframe class="ytifr" width="1280" 
  height="720"
  src="https://www.youtube.com/embed/KMPkI"
  title="YouTube video 
  player" frameborder="0" allow="accelerometer;  autoplay;  clipboard - write;
  encrypted - media; gyroscope;
  picture - in -picture " allowfullscreen></iframe></div></div>`;
})
<div class="ifpss"></div>
<a href="#" id="ytif" class="watch-more buttontext">
  <p>Voir la vidéo de présentation &rarr;</p>
</a>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Something like

var myobj = document.getElementById("demo");
myobj.remove(); 

could help

Have a look at https://www.w3schools.com there are good examples for beginners

about 4 years ago · Juan Pablo Isaza Relatório

0

Why not just put your link inside the target div? Then it'll be naturally overwritten by your existing code.

const btnif = document.querySelector("#ytif");
const ifpss = document.querySelector(".ifpss");

btnif.addEventListener('click', () => {
  ifpss.innerHTML = `<div class="ytifrore"><div class="ytiframe"><div 
  id="closep"> &times;
  Fermer la page </div><iframe class="ytifr" width="1280" 
  height="720"
  src="https://www.youtube.com/embed/KMPkI"
  title="YouTube video 
  player" frameborder="0" allow="accelerometer;  autoplay;  clipboard - write;
  encrypted - media; gyroscope;
  picture - in -picture " allowfullscreen></iframe></div></div>`;
})
<div class="ifpss">
  <a href="#" id="ytif" class="watch-more buttontext">
    <p>Voir la vidéo de présentation &rarr;</p>
  </a>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Just add <a href="#" onclick="ifpss.innerHTML=''"> to make the text a link that deletes the ifpss html.

const btnif = document.querySelector("#ytif");
const ifpss = document.querySelector(".ifpss");

btnif.addEventListener('click', () => {
  ifpss.innerHTML = `<div class="ytifrore"><div class="ytiframe"><div 
  id="closep"> <a href="#" onclick="ifpss.innerHTML=''">&times;
  Fermer la page</a> </div><iframe class="ytifr" width="1280" 
  height="720"
  src="https://www.youtube.com/embed/KMPkI"
  title="YouTube video 
  player" frameborder="0" allow="accelerometer;  autoplay;  clipboard - write;
  encrypted - media; gyroscope;
  picture - in -picture " allowfullscreen></iframe></div></div>`;
})
<div class="ifpss"></div>
<a href="#" id="ytif" class="watch-more buttontext">
  <p>Voir la vidéo de présentation &rarr;</p>
</a>

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