Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6871493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:48:48+00:00 2026-05-27T03:48:48+00:00

Totally stumped here. Trying something pretty easy, but it’s not working: $(input.input1, textarea.input1).focus(function(){ $(this).addClass(input2).removeClass(input1);

  • 0

Totally stumped here.
Trying something pretty easy, but it’s not working:

$("input.input1, textarea.input1").focus(function(){
    $(this).addClass("input2").removeClass("input1");
});
$("input.input2, textarea.input2").blur(function(){
    $(this).addClass("input1").removeClass("input2");
});

Basically the blur isn’t firing.
I click on the input box and the box changes.
I click away from the box and nothing happens.
Any help with this would be awesome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:48:48+00:00Added an answer on May 27, 2026 at 3:48 am

    You need to use a delegated handler as the input doesn’t have class input2 at the time the handler is applied.

    $(document).on('focus','input.input1, textarea.input1', function() {
        $(this).addClass('input2').removeClass('input1');
    });
    $(document).on('blur','input.input2, textarea.input2', function() {
        $(this).addClass('input1').removeClass('input2');
    });
    

    There are probably better ways to do this, however. I’d suggest using a third class to mark the inputs that need the class toggled, then just toggle the classes when the event occurs.

    $('.needsToggle').on('focus blur', function() {
         $(this).toggleClass('input1 input2');
    });
    

    If they always have class input1 to start, you could use that instead of needsToggle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm totally stumped here, so any ideas would be appreciated. I have a RichFaces
I am totally stumped here. I have a bunch of messages, each within a
I'm totally stumped with this one and hope someone could help me out here:
I am totally stumped on this one. I am getting a Object reference not
I have this school assignment that I've been working on and am totally stumped
Totally new to Spring & Java development but working on a project for a
I have been trying to learn Prolog, and am totally stumped on what the
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray
I'm getting a totally bizzare error trying to compile a C program using GCC.
I'm totally new to both java and java Server worlds... But I've a good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.