Search code examples
javascriptjquerylive

Live checking value of textarea


I have a textarea that have a id upload-message. And this jvavscript:

 // step-2 happens in the browser dialog
            $('#upload-message').change(function() {
                $('.step-3').removeClass('error');
                $('.details').removeClass('error');
            });

But how can i check this live? Now, i type in the upload message textarea. And go out of the textarea. Than the jquery function is fired. But how can i do this live?

Thanks


Solution

  • With .keyup:

    $('#upload-message').keyup(function() {
        $('.step-3, .details').removeClass('error');
    });
    

    However, this'll keep on running for every keypress, which in the case you provided does not make sense.

    You should rather bind it once with one:

    $('#upload-message').one('keyup', function() {
        $('.step-3, .details').removeClass('error');
    });
    

    ...so that this event will only fire once.