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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:15:29+00:00 2026-06-07T02:15:29+00:00

I am at a loss here, never had a problem with this before. I

  • 0

I am at a loss here, never had a problem with this before.
I cannot get focus() to work at all in any browser. I’m using jquery and can’t even get it to work with standard javascript. I tried adding the timeout as well but still nothing. All I get in the alert is “undefined”.

Here is the input

<input type="text" name="SearchBox" id="SearchBox" class="SearchBox" />

and here is the jquery

$(document).ready(function(){
    setTimeout(function(){
        $("#SearchBox").focus();
    }, 0);
    alert($("*:focus").attr("id"));
});

I’ve stripped the page down to just the above in case something was interfering with it but still no success. It has to be something simple I’m missing!!!!

  • 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-07T02:15:31+00:00Added an answer on June 7, 2026 at 2:15 am

    The searchbox will not get the focus until the document ready handler completes.

    When you call setTimeout, even if the timeout is set to zero, JavaScript will not handle that timeout until the current function is complete. This is because JS is single threaded.

    Calling setTimeout with a timeout of zero is like saying “Here’s something I’d like you to do, once this function has completed.”

    Hence, the searchbox won’t get focus until after the alert is called.

    An example

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

Sidebar

Related Questions

I'm sorta at a loss to why this doesn't work considering I got it
I'm at a bit of a loss here, forgive me if this has already
Alright, I'm at a loss here I'm getting errors for any locally hosted js
I am totally at a loss here and can't find a solution to this
Ok, I'm completely at a loss here. I've used DataAnnotations attribute DisplayName successfully using
Alright, hopefully someone can help me with this because I'm at a loss here.
I'm at a loss and hoping to find help here. What I'm trying to
I'm at a loss, I can't see the reason something as simple as this
I'm at a loss why this loop stops after the first item. Can someone
Simple issue but I'm at a loss to debug this further. I followed the

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.