Javascript – Show keyboard for div with contenteditable=”true” in ios


I have a div with contenteditable="true". How can I set focus on this div via javascript(if it possible on pure js, without jquery)?

Best Solution

Prior to iOS 6 this wasn't possible, but thankfully they've changed that. You can't do it in general for a website, but if you are embedding a UIWebView in your application you can do it now:

UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.keyboardDisplayRequiresUserAction = NO;

Then your element.focus() will work and bring up the keyboard as desired.

More info on what changed with iOS 6 & WebKit: