GuerillaRadio
GuerillaRadio

Reputation: 1297

Jquery Check If Input Field Has Changed On Each Keyup

I've got this jQuery script which checks to see if an input field has changed, and if it has, it adds a class to an icon (which then changes colour to let the user know they have filled in the field).

$('.input-icon input').change(function() {
    $(this).next(".icon").addClass('complete');
});

It works but only when the field in question is deselected after the text has been input into it. What I need is for this to run each time a key is pressed and update accordingly.

Thanks guys.

Upvotes: 0

Views: 1198

Answers (1)

Adil Shaikh
Adil Shaikh

Reputation: 44740

See http://api.jquery.com/keyup/

$('.input-icon input').on('keyup',function() {
    // check if input has something in it
    $(this).next(".icon").addClass('complete');
});

DEMO

Upvotes: 1

Related Questions