zag2010
zag2010

Reputation: 509

My class selector isn't working for parsley-error

I'm trying to act on fields which have the parsley-error class, unfortunately the following code isn't working.

$('.parsley-error').on('focusin', function() {
    console.log('yep');
});

if I change it to this:

$('input').on('focusin', function() {
    console.log('yep');
});

then that works, so I know the code is being run ... just that the selector isn't working. Any help is, of course, much appreciated.

Upvotes: 0

Views: 167

Answers (1)

Marc-André Lafortune
Marc-André Lafortune

Reputation: 79562

When you are calling $('.parsley-error').on..., your jQuery set is probably empty, as there aren't any errors yet. So your code does nothing.

You probably want to use delegated events $(document).on('focusin', '.parsley-error', ...) instead. Or use the parsley events to do stuff when there's an error.

Upvotes: 2

Related Questions