1

I want to fire off an event before my focus on a textarea (i.e. before the keyboard appears on iOS).

Is this possible?

My code to handle the focus is here:

$(document).on('focus', 'textarea', function() {
    console.log("focus event");
});
AlexVogel
  • 10,601
  • 10
  • 61
  • 71
Gary
  • 395
  • 2
  • 7
  • 24

2 Answers2

2

Try touchstart Event

$(document).on('touchstart', 'textarea', function() {
console.log("touchstart event");
  });
Arunkumar
  • 5,150
  • 4
  • 28
  • 40
  • Unfortunately this doesn't work, I fire off an event in there but the keyboard still opens before anything completes. – Gary Jul 04 '14 at 10:22
  • I might need to re-ask this question in a new format, as the touch start happens when they put their finger down, and the keyboard appears when they lift their finger up. So a standard "touch" on a mobile device is an instant touchstart into blur, at which point the keyboard opens. If there is even the slightest delay, the keyboard does open first (before the code is hit). I've spent a week or so now looking how to control the keyboard appearance but have had no luck. Do you have any ideas please? Will open a new question as well. Thanks – Gary Jul 16 '14 at 13:50
2

I would use the focusin event note that this event catch the child elements focus as well.

focusin: sent before first target element receives focus

$("div").focusin(function(){
    $(this).css("background-color", "#FFFFCC");
}); 

Check here to know more about the focus events order

Flavien Volken
  • 19,196
  • 12
  • 100
  • 133