Ruby
Ruby

Reputation: 969

Capture focus event for all textboxes - JQuery

I have many textboxes in a form. When its respective value fails validation a class 'has-error' is applied, which adds a red border to the textbox.

I would like to undo this class if that textbox get focus.

Something like

$(document).on('focus',find(':input'),function(){
    $(this).removeClass('has-error');
});

How is this done?

Upvotes: 0

Views: 307

Answers (2)

tymeJV
tymeJV

Reputation: 104795

Just do:

$(document).on("focus", "input:text.has-error", function() {

Upvotes: 1

You don't need find(':input') just use ':input.has-error'

$(document).on('focus', ':input.has-error' ,function(){
   $(this).removeClass('has-error');
});

And also make sure your code in DOM Ready

Upvotes: 3

Related Questions