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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:04:20+00:00 2026-05-22T03:04:20+00:00

I am trying to focus to a div (fancybox modal) when user click on

  • 0

I am trying to focus to a div (fancybox modal) when user click on a dropdown box. I have tried setting tabindex on the div. It focus alright however display a scrollbar at the bottom of the modal window.

Having read that links, input elements, textareas, etc can be set to focus on, I have tried focus a hidden input in the modal div with no avail.

more details: it is a user registration page with all countries and cities loaded hidden in the page. a fancybox modal pops up with content of the hidden countries and cities displayed when user click on the city dropdown box. from there, user can click through country, state then city. in the end, the chosen city gets filled in the previous dropdown and fancybox closed.

The problem is that user clicks on dropdown and the focus stays there after the fancybox popsup.

Code:

$("select[name=current_home]").click(function() {
    $.fancybox({
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'overlayShow'   : false,
        'titleShow'     : false,
        'width'         : 300,
        'content'       : '<div id="countries">' + $('#countries-box').html() + '</div>',
        'onComplete'    : function() { $('#countries').focus(); },

    });
   //       $('#countries input[name=focusme]').focus();
});

the countries-box hold the hidden countries and cities. I wasn’t using the onComplete provided by fancybox as you can see the above commented line. I tried both and no difference.

any solution?

  • 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-22T03:04:20+00:00Added an answer on May 22, 2026 at 3:04 am

    Ok, you’re trying to focus <div id="countries>, and divs can’t be focused, neither they transfer focus to inside focusable elements.

    You need to focus an input, select, textarea or button inside your div on it’s onComplete event firing, and a good way would be to focus the first one, like this:

    $.fancybox({
        ...
        'onComplete' : function(){ $('#countries :input:visible:enabled:first').focus()}
        ...
    });
    

    :input checks for input, select, textarea and button elements, as explained in jQuery API

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

Sidebar

Related Questions

I am trying to set a focus on a dropdown within GridView(gridViewDropDown class) when
I'm trying to set the default focus on an input box when the page
I am trying to do, so when a user marks/put focus on an input
I have a div that is scrolling vertically. I, however, really want it to
I am trying to make a div, that when you click it turns into
I am trying to achieve a modal overlay using jQuery. When a user clicks
I have a popup div and want to hide it when users click outside
Is it possible to focus on a <div> using JavaScript focus() function? I have
I'm trying to change the focus whenever a user presses tab on the last
Using jQuery I am trying to set focus for (CSS purposes) to a particular

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.