0

For this question there are some other related questions which explains the possibility of the re enabling of input field or button using disabled attribute.

But my requirement is for re-enablebing the div click functionality after some action. Currently I'm using .off() for disabling the click function of a div after first click.

But I'm not able to re-enable it back.

Code where div is disabled

    $(document).ready(function(){
       // Will ask for city through voice when user click on the instruction box.
        var accessBtn = $('#skitt-listening-box');
        $("#skitt-listening-box").click(function(){
          $(this).off('click'); // code to disble div from click
          //some functionality
        });

  });

Code where div is enabled:

if(IsEmail($(".voice_email").val())) {
              //some functionality
              //Should re-enable the div to click here              
          });
6
  • how about adding some code Commented Sep 2, 2016 at 11:25
  • Sounds like you need on() and toggleclass()? Commented Sep 2, 2016 at 11:31
  • sure, @RST I will do it now. Commented Sep 2, 2016 at 11:34
  • @RST can you please help me now? Commented Sep 2, 2016 at 11:43
  • I think it is best to use .prop("disabled",true)/.prop("disabled",false) to disable/enable the button. Your if(IsEmail(...)) should be in an eventhandler though otherwise it will not run. Commented Sep 2, 2016 at 11:53

2 Answers 2

1

If I were you i try adding css classes to describe state.

In your way:

$(document).ready(function(){
   // Will ask for city through voice when user click on the instruction box.
    var $accessBtn = $('#skitt-listening-box');
    $accessBtn.click(function(){
       if($(this).hasClass('click-available'){
         //do action
         $(this).removeClass('click-available');
       }
    });
});

And to enable click:

if(IsEmail($(".voice_email").val())) {
    $accessBtn.addClass('click-available');            
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou for that little hack @manveru , it worked like a pro :)
0

You can use this code:

function addClickFunctionality() {
  $("#skitt-listening-box").on('click', function(){
    $(this).off('click'); // code to disable div from click
    // some functionality
  });
}

$(document).ready(function() {
  // Will ask for city through voice when user click on the instruction box.
  addClickFunctionality();
});


// re-enable click handle in some action
if(IsEmail($(".voice_email").val())) {
  // some functionality
  addClickFunctionality();              
});

1 Comment

what do you mean by addClickFunctionality(); Can you make it more clear?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.