Good day. Please tell me ways to block the effect of this function here:

$('#sendcustomcake').click(function(){ createCustomBooking(); }); 
Already in another script and in the condition:

 $('document').ready(function() { $('#sendcustomcake').on('click', function() { $('.refield').each(function() { if ($(this).val() != '') { // Если поле не пустое удаляем класс-указание $(this).removeClass('empty_field'); } else { // Если поле пустое добавляем класс-указание $(this).addClass('empty_field'); document.getElementById('#sendcustomcake').removeEventListener('click', createCustomBooking); } }); 

I try to do this with removeEventListener, but this does not help.

  • off - unsubscribe handler - Grundy
  • @Grundy, I did not quite understand you. What did you mean? - Webdev96
  • You want to remove the click handler, in jQuery the off method is responsible for this - Grundy
  • @Grundy, document.getElementById('#sendcustomcake').off('click', createCustomBooking); } document.getElementById('#sendcustomcake').off('click', createCustomBooking); } Like this? - Webdev96
  • of course not. Decide whether you use jQuery or not. - Grundy

1 answer 1

Just save the function to a variable and use the variable for control.
The same trick with setTimeout and clearTimeout.

 const click = () => { console.log('click'); } $('.click').on('click', click); $('.unclick').click('click', function() { console.log('Эвент снят'); $('.click').off('click', click); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="click">Click</button> <button class="unclick">Unclick</button>