SaladTato - Agario SaladTato - Agario - 6 months ago 18
Javascript Question

How to check if a textbox is clicked on

I have a keyup function on my script and when I type into one of my text boxes it triggers my hotkey which hides the text box so it makes it impossible to type in it. Please help.

$(document).keyup(function(e){
if(e.which == 67){
if($('#main').css('opacity') == 0) {
$("#cHideChat").click();
}
}
});


I want something like this but I don't know the right word to put here.

$(document).keyup(function(e){
if(e.which == 67){
if($("#chat-input").is("clickedOn")){
return false;
}
else{
if($('#main').css('opacity') == 0) {
$("#cHideChat").click();
}
}
}
});

Answer
Try the following:

$(document).keyup(function(e) {
    if(e.which == 67){
        if (e.target.id == "chat-input") {
            return false;
        }
    }
    else {
      if ($('#main').css('opacity') == 0) {
          $("#cHideChat").click();
      }
    }
  }
});