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

175
Views
How to detect (when trying to append a created element) if that element has been created once before with JavaScript

So I'm trying to build a gif/webm/png etc viewer, right now I'm creating elements to then set the file selected to that img (or if it is a webm file, then we'll set it's src to a video element)

Now I'm also building a hide button (the element I want to see if it's already appended) to hide the image or video when it is clicked, so I want to create it... then append it when an image like a gif or png is chosen, but I have made a listener to detect if the file is a webm.

I also want to detect if the document already has the hide button, so therefore I can assign a hide button to either the img element or video separately element because as on my codepen the hide button won't work to hide the video when the img is created first then the video and so forth.

Basically I want to detect if the hide button has been appended before for the img element and/or video element (to prevent duplicates on the page) then delete it and create a new one that will read for the new video or img element.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

So after awhile of trying out things, I came to a conclusion that an if statement could work.

const btnOne = document.createElement("a");
const btnTwo = document.createElement("a");

if(btnOne !== null) {
  if(btnOne.parentNode) {
     btnOne.parentNode.removeChild(btnOne);
  }
  document.body.appendChild(btnTwo);
} else if(btnOne == null){
  document.body.appendChild(btnTwo);
}

this is basically how I did it.

about 4 years ago · Santiago Trujillo 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!