1

Considering the following, how can I enable a disabled element on click?

$("element").click(function(){
    //enable element
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Babiker
  • 18,300
  • 28
  • 78
  • 125

2 Answers2

3

The best I could come up with is:

$('label').click(
    function(){
        $(this).next(':disabled').removeAttr('disabled');
    });

Since the disabled element itself doesn't, at least in Chrome 8/Ubuntu 10.10, respond to click events.

This does assume, of course, that the label precedes the disabled element, and doesnt', in its current form, check that the label corresponds to the next disabled element.

JS Fiddle demo of the above.


Edited to revise the approach, so clicking on the label affects only the relevant input:

$('label').click(
    function(){
        var relevantInput = $(this).attr('for');
        $('#' + relevantInput)
            .removeAttr('disabled');
    });

JS Fiddle demo

David Thomas
  • 249,100
  • 51
  • 377
  • 410
0

Dupilicate: Jquery event on a disabled input.

Community
  • 1
  • 1
Babiker
  • 18,300
  • 28
  • 78
  • 125