Skip to content

Instantly share code, notes, and snippets.

@sandro
Created May 23, 2012 00:44
Show Gist options
  • Save sandro/2772590 to your computer and use it in GitHub Desktop.
Save sandro/2772590 to your computer and use it in GitHub Desktop.
playground for testing ios web autofocus
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<a href="">link</a>
<input type="text" id="in"/>
<button>hi</button>
<script type="text/javascript">
$.fn.triggerHTMLEvent = function(type) {
var element, event;
if (element = this[0]) {
if (document.createEvent) {
event = document.createEvent('HTMLEvents');
event.initEvent(type, true, true);
element.dispatchEvent(event);
} else if (element[type]) {
element[type]();
}
}
return this;
};
$(function() {
var x = function(){$('input').focus()};
var auto = function(){$('body').append('<input type="text" autofocus/>')}
var field = $('#in');
$('button').click(function() {
var newf = $('<input type="password"/>').appendTo($('body'));
newf.attr('autofocus', true);
newf.show();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment