Babiker
Babiker

Reputation: 18798

How use mousedown/click events for disabled objects?

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

$("element").click(function(){
    //enable element
});

Upvotes: 1

Views: 2103

Answers (2)

David Thomas
David Thomas

Reputation: 253436

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

Upvotes: 3

Babiker
Babiker

Reputation: 18798

Dupilicate: Jquery event on a disabled input.

Upvotes: 0

Related Questions