¿Cómo usar eventos de mousedown / click para objetos deshabilitados?

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

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

preguntado el 09 de enero de 11 a las 00:01

Is the element that is being "enabled" the same as the one being clicked? -

@patrick - yes, the element being click is the one that needs to be enabled. -

2 Respuestas

Lo mejor que se me ocurrió es:

$('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.


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

Demostración de JS Fiddle

Respondido el 09 de enero de 11 a las 04:01

contestado el 23 de mayo de 17 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.