I have a global javascript variable called "BTN":
var BTN;
When the user does certain things a function gets called which assigns a DOM-Button-element to this variable (via the following code):
BTN = document.createElement("BUTTON");
var text = document.createTextNode("click to remove me again");
BTN.appendChild(text);
When the user clicks on the button, the button is supposed to disappear. To this end, I created the following Event-Listener:
$(BTN).on("click", function(){
$(this).remove();
});
However, when I click on the button, nothing happens.
I don't understand what's wrong. The most ridiculous thing is this: clicking the button is not the only way the user can get rid of it. When he clicks a certain area, a function is called that (among other things) removes the button as well, simply by the following line of code:
if(BTN) $(BTN).remove();
This works like a charm. But the other method (where the user clicks on the button) does not work. I have no clue whatsoever how this can be!