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 9213713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:48:47+00:00 2026-06-18T01:48:47+00:00

I have to admit, I came up with this solution by pure intuition from

  • 0

I have to admit, I came up with this solution by pure intuition from seeing many jQuery scripts during all the time I’ve been experimenting and learning on my own.

Since I don’t have anyone to ask in person these kind of questions, that’s why I come here for help and guidance.

—

Inspired by Wufoo’s plans’ forms where the row you need to focus is highlighted while filling out the form, I created this script (I am not a jQuery or JavaScript guru, I’m still learning and practicing):

//Improve usability by highlighting the row the user needs to focus on:
$(function() {
        //When input element has focus
        $('input').focus(function(){
            //Add the class to its corresponding row
            $(this).parent().parent('.row').addClass('focus'),
                //And when it loses focus
                $('input').blur(function(){
                    //Remove the class
                    $(this).parent().parent('.row').removeClass('focus');
                });
        });
});

So I was wondering if this script has a way of being written better or optimized/shorten in any way. If not, and the way I wrote it’s Ok, that’s fine, all I’d like to learn is ways of optimizing code when possible, that’s all.

I created a Demo in Codepen if you want to check it out.

Thanks in advance.

  • 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-06-18T01:48:48+00:00Added an answer on June 18, 2026 at 1:48 am

    You can do this:

    //Improve usability by highlighting the row the user needs to focus on:
    $(function() {
            $('input').focus(function(){
                $(this).closest('.row').addClass('focus'); // Change here                    
            }).blur(function(){ // Change here
               $(this).closest('.row').removeClass('focus'); // Change here
            });
    });
    

    Or even shorter!

    $(function(){
        $("input").on("focus blur", function(){
            $(this).closest(".row").toggleClass("focus");
        });
    });
    

    You did 1 thing totally wrong!! Each time you focus you bind a new blur to each input!

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

Sidebar

Related Questions

I've seen this and I have to admit I'm pretty impressed: (source: blogspot.com )
This is my first post and I have to admit, I am terrible at
I have this simple script that I'm working on. I must admit, I'm totally
I came from PHP, Python and Django are new to me. I have a
I have to admit, I don’t yet understand this. I am sure if I
I have to admit that I'm new to Java and Android. db4o seems to
First, I have to admit I screwed up a little with CVS. I had
After looking around (for not terribly long I have to admit) I wonder if
I did my programming before integrating into a design and I have to admit
I've been doing project Euler for a few days, and I have to admit

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.