-1

I have two click functions, on function is for adding vacation in a list, the other function is for removing vacation from the list. When I add vacation to the list, I dont want to be able to click on that specifik button again .vacation-btn. If I remove specifik vacation from the list, then I want to be able to click that .vacation-btn again. I have tried with jQuery(this).off('click'); and Its working, but then when I remove vacation from the list I want to add the click event again.

jQuery("tr td .list").live('click', function(e) {
    var test = jQuery(this).closest('tr');
    jQuery(test).remove();
});
jQuery(".vacation-btn").on('click', function(event) {
    var id = jQuery(this).attr('id');
    event.stopImmediatePropagation();
});
Tony
  • 105
  • 2
  • 11

1 Answers1

0

Possible approach:

<script>
function f1() {
  console.log("btn1");
  $("#btn1").off("click");
  $("#btn2").on('click', f2);
}
function f2() {
  console.log("btn2");
  $("#btn2").off("click");
  $("#btn1").on('click', f1);
}
$(document).ready(function() {
  $("#btn1").on('click', f1);
});
</script>
<button id="btn1">button 1</button>
<button id="btn2">button 2</button>

Another way is to check for content, you are adding\removing, or just have a bool indicator.

Alex Yokisama
  • 1,021
  • 7
  • 8
  • If I add jQuery(this).off('click'); then I want that specifik button, to be clickable again when I remove that specifik element from the list. – Tony Mar 08 '18 at 13:52
  • Suppose `f1()` is add function and `f2()` is a remove function. Then f1 disables itself and enables f2 and f2 disables itself and enables f1. So, `add` wil be clickable after `remove` – Alex Yokisama Mar 08 '18 at 13:56