Home > OS >  Remove element after success click from DOM - Test Angular
Remove element after success click from DOM - Test Angular

Time:09-23

how do I please test if deleting the link element works for me? With link.remove () I try to remove the element from the DOM, but I don't know whether it works.

var downloadURL = URL.createObjectURL(data);

var link = document.createElement('a');

link.href = downloadURL;
link.download = fileName;
link.click();
link.remove();

Thank you for help.

CodePudding user response:

You have to append it document.body.appendChild(link); and then you can remove it in DOM document.body.removeChild(a);

var downloadURL = URL.createObjectURL(data);
var link = document.createElement('a');

// Add this line
document.body.appendChild(link);

link.href = downloadURL;
link.download = fileName;
link.click();

// Add this line
document.body.removeChild(link);
  • Related