JavaScript -- transfer of the button as part of the variable
-
When the event is going on in the button, I can tell her how
this
and when the event occursinput
How do you get the button?$("#button").bind("click", function() { $(this).remove(); // например, удалить кнопку из DOM });
$("#input").bind("keyup", function() {
// как тут удалить кнопку? $("#button").remove() не в счёт
});
-
I don't know. But you can keep this button first into the variable and then use:
var button = $("#button").on("click", function() { $(this).remove(); // например, удалить кнопку из DOM });
$("#input").on("keyup", function() {
button.remove();
});
Another option, https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/bind and establish
this
or default parameter for the processor, but the link will be lostthis==input
inside the processor:var button = $("#button").on("click", function() {
$(this).remove(); // например, удалить кнопку из DOM
});var keyUpHandler = function() {
// this === $("#button")
this.remove();
}.bind(button);$("#input").on("keyup", keyUpHandler);
Or
var button = $("#button").on("click", function() {
$(this).remove(); // например, удалить кнопку из DOM
});var keyUpHandler = function(btn) {
// this === input
btn.remove();
}.bind($("#input")[0],button);$("#input").on("keyup", keyUpHandler);