I am pretty new to JavaScript and js-libraries. I am using zepto.js and want to focus on an input field with $('input').focus();
after I am doing a submit (appending an element to a list). I used to work with jQuery but due to performance I am using Zepto now. The same code worked fine with jQuery. I found just few documentation on .focus()
and .blur()
in Zepto, but as I understood, it should work.
I also tried getElementById('input').focus();
but that didn't work aswell.
The whole code:
$(document).ready(function(){
$('button').tap(function(){
var toAdd = $('input[name=list-element]').val();
if (toAdd == ''){
return false;
}
else {
$('#liste').append('<div class="item item-red">' + toAdd + '</div>');
};
$('input').val('');
$('input').focus();
});
Found a solution myself:
I deleted $('input').focus();
in the script.js and added the following script directly in the HTML file:
<script type="text/javascript">
function focus(){
document.inputform.list-element.focus();
};
</script>
And edited the button-tag: <button onclick="focus()">GO ▼</button>