0

Is there a way to tell jQuery to only target elements that as disabled?

https://jsfiddle.net/o80cqp4h/

$(document).on("click", "input", function () {
   console.log('click');
   $(this).prop('disabled', false);
});
2
  • Disabling an item removes the ability to click it. Think about a button, the purpose of disabling a button is so it cannot be clicked. Commented Oct 27, 2015 at 18:15
  • The problem is with disabled="disabled", you can never trigger click event. Commented Oct 27, 2015 at 18:15

1 Answer 1

1

jQuery ignores clicks on disabled elements (sort of), so the trick is to detect the click higher up the chain, and then find out if it was on an input element:

$(document).on("click", function (e) {
    $clicked = $(e.toElement);
    if ($clicked.is("input:disabled")) {
        $clicked.prop('disabled', false);
    }
});

If you have to support firefox, you have to get even hackier.

https://jsfiddle.net/o80cqp4h/3/ <-- with firefox support

https://jsfiddle.net/o80cqp4h/1/

Sign up to request clarification or add additional context in comments.

4 Comments

Ahh firefox, just added a really hacky solution to support that
well, not really. I can't change the value of the input after it "became active"
Thanks for not being one of the others to just say you can never do this. I know I had seen it done before.
I may keep playing with it, because jsfiddle.net/o80cqp4h/4 does not work. (When the input is later added dynamically) I could always run the build function after adding it.

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.