0

I have a part of code, where I create new elements on the fly and make them focusable.

The code is more complex, but here is a reproducible part on jsfiddle (when you click enter the next element is created and then focus is assigned to it):

$("body").on( "keypress", ".field", function(e) {
  if ( e.keyCode  == 13 ) {
      $(this).after('<p class="field" contenteditable="true"><br></p>')
      $(this).next().focus();
      e.stopPropagation();
      e.preventDefault();
  }
});

This works as expected in desktop browsers, but it failed to focus the next element on ipad (and may be on iphone)

Salvador Dali
  • 199,541
  • 138
  • 677
  • 738

1 Answers1

-1

Apparently IOS/Safari only "accepts" the focus when inside a touch event handler. I triggered a touch event and inserted the .focus() inside it. I tried this on my iPhone3S/Safari and it works:

Demo.

Actual Stackoverflow question.

Community
  • 1
  • 1
user3995789
  • 3,422
  • 1
  • 16
  • 31