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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:20:49+00:00 2026-05-28T01:20:49+00:00

I have a div with tabindex attribute set to ‘-1’ so it can gain

  • 0

I have a div with tabindex attribute set to ‘-1’ so it can gain focus on mouse click.

<div tabindex='-1'></div>

.div:focus{//some style}

I want to do something with Jquery when the user clicks the div but only if it is selected (after second click).

$('div').click(function(){
if($(this).is(':focus')){
//do something
}
});

But it doesn’t work, the action is immediately triggered.

EDIT: Code included.

  • 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-28T01:20:49+00:00Added an answer on May 28, 2026 at 1:20 am

    I would check the 2nd click with a flag, see my answer here

    1. I used a flag isClicked to determine if it the 1st click or 2nd. If it is 1st click, set the flag to true and return ((i.e) do nothing). Next time, the flag is checked for true which means it is 2nd click, and the add code below to do what you want.

      var isClicked = false;
      
       $('div#myTest').click(function(){
      
       //do nothing on 1st click
       if (isClicked == false) {
          alert('Clicked 1st time');     
          isClicked = true;
          return;
       }
      
       //do whatever u want on second click    
       alert('Clicked 2nd time');     
      
       });
      
    2. Reset the flag when it is clicked outside the div, the below code does that…

      // to check it is clicked outside div
       $(document).click(function(e){
        if($(e.target).is('#myTest'))return;    
      
        //reset to
        isClicked = false;
      
       });
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I have a <DIV> within an HTML <SELECT> tag? e.g.: <select tabindex=2 name=agegrp
I have a div container and have defined its style as follows: div#tbl-container {
I have a div tag styled through CSS. I set the padding to 10px
I have a div with a set height of 200, and sometimes there's enough
I have designed a HTML for with the tabindex set to the fieds. There
Hope you can help me with this, (again in some cases!) I have a
I am trying to focus to a div (fancybox modal) when user click on
I have a div that has been given a tabindex, when the div is
I wish to be able to click on a div and have it select
I have a buyer form, called Buyer.php: <form method=post action=check_buyer.php id=LoggingInBuyer> <div style=width:265px;margin:0; padding:0;

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.