I'm currently writing a browser script (for use in Tampermonkey/Greasemonkey) (and learning JS in the process!), and I have a lot of occurrences like this:
let btn = document.querySelector("#unwantedButton");
if (btn) {
btn.parentNode.removeChild(btn);
}
That is, I want a certain element to be removed, if it exists.
Is there any way to write this more concisely and elegantly? That would save me a lot of lines in this project, and most importantly, teach me some JS best practice. :-)
Thank you for helping a JS noob!