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.
I would check the 2nd click with a flag, see my answer here
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.
Reset the flag when it is clicked outside the div, the below code does that…