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

  • Home
  • SEARCH
  • 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 8782657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:37:21+00:00 2026-06-13T20:37:21+00:00

When the page loads, I want to focus and highlight (border color or background

  • 0

When the page loads, I want to focus and highlight (border color or background color change) an input control. How can I do it? This is what I got so far.

<script type="text/javascript">
    $(function () {
        $("#txt1").focus();            
    });
</script>
  • 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-13T20:37:23+00:00Added an answer on June 13, 2026 at 8:37 pm

    Take a look at CSS :focus selector. And just specify CSS class like:

    #txt1:focus {
        border-color:red;
    }
    

    As it is not supported by older browsers (IE7 plus some other). You may want to do that with JS.

    $("#txt1").focus(function(){ $(this).addClass("focused")});
    $("#txt1").blur(function(){ $(this).removeClass("focused")});    
    

    Where focused is defined like this:

    #txt1.focused {
       border-color:red;
    }
    

    EDIT:

    Jquery.focus docs.

    $("#txt1").focus(function(){ $(this).addClass("focused")});
    

    Line above simply binds a handler to focus event and does not change a focus or execute it immediately. In order to get a field focused on page load another line should be added after that one:

    $("#txt1").focus();
    

    This one will set a focus on selected element and run a handler attached previously.
    Shorter notation:

    $("#txt1").focus(function(){ $(this).addClass("focused")}).focus();
    

    Demo with element autofucused on page load

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

Sidebar

Related Questions

When my Silverlight page loads, I want to set focus on a control. Simple
Got some code which loads an input box, and then below this is an
I want to set focus to a particular form field on page load. This
Hi I want to focus on the SuggestBox as page loads. I could not
As soon as a page loads, I want the focus to jump to a
I have text div i want fadeout effect on this when page loads or
I have a stripes action page. and When the page loads, I want to
I want to set focus on inputText field in JSF on page load. How
Am using Django's form for my login page. I want to set focus to
I have few textboxes on one page and one user control. What I want

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.