I am trying to delete or empty the element using JAVASCRIPT, but it must be the element we pass into the function as a parameter. It has to work onClick for example, everything has to work dynamically, but I can't get it to work. Here is my code so far:
function deleteElement(selector, type) {
switch (type) {
case `${"delete" || "remove"}`:
document.querySelector(selector).remove();
break;
case "empty":
document.querySelector(selector).innerHTML = "";
break;
// if user doesn't enter desired outcome, the element will be deleted by default
default:
document.querySelector(selector).remove();
break;
}
}
My question is, using this code how can I perform action on dynamically selected element?