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

252
Views
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 answers
Answer question

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 Report

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 Report

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