Case
Case

Reputation: 4272

Jquery on click input does not work if input is disabled

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);
});

Upvotes: 0

Views: 43

Answers (1)

dave
dave

Reputation: 64657

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/

Upvotes: 1

Related Questions