user1691585
user1691585

Reputation: 5

How do I fade in :focus when an input box is selected?

I'm trying to work out how to fade in the :focus pseudo selector when an input box is selected.

I've tried the following method but it doesn't seem to be working. I don't think I've set the parameters properly so some help would be welcome here.

$('input').click(function() {
    $('input').fadeIn('fast', function() {
        $('input').focus();
    });
});​

Upvotes: 0

Views: 850

Answers (1)

Stinodotbe
Stinodotbe

Reputation: 402

I don't know if I understand your question correctly, but maybe this could be the solution:

jQuery('input').on('focus', function() {
    jQuery(this).fadeIn('fast');
});

So what happens is you check your inputbox and add a listener when you focus on it. Then you tell jQuery when it happens the box has to fade in. When you want to do this on all inputboxes on your page, the safest way to do it is like this:

jQuery('input').each(function() {
    jQuery(this).on('focus', function() {
        jQuery(this).fadeIn('fast');
    });
});

Upvotes: 1

Related Questions