been working on a thing for fun. I was wondering how I could delete an html element if I just clicked it on any website or html file. No jquery or other libraries, just vanilla JS. If the question is hard to understand here’s an example:
-Website loads
-I see a p tag or img tag or just any tag and I don’t want to see it any more so I just click it and it deletes.
-I’m now happy because of what I’ve done.
currentCode:
window.addEventListener("click", function(i) {
//Code to remove something? idk... Not that good with js atm...
}, false);```
>Solution :
window.addEventListener("click", function(e) {
const target = e.target;
target.remove();
}, false);
<button>a</button>
<button>a1</button>
<p>paragraph...</p>
<h1>header...</h1>