1
'Cause I can’t type text into input ".task-act" which was created with the jQuery?
$(function(){
function onTarefaDeleteClick(){
$(this).parent('.tarefa-item').hide('slow', function(){
$(this).remove();
});
}
$('.tarefa-delete').click(onTarefaDeleteClick);
});
$(function(){
function onTarefaItemClick(){
var text = $(this).children('.tarefa-texto').text();
var html = '<input type="text" ' + 'class="tarefa-edit" value="' + text + '">';
$(this).html(html);
$('.tarefa-edit').keydown(onTarefaEditKeydown);
}
$('.tarefa-item').click(onTarefaItemClick); //
});
function onTarefaEditKeydown(event){
if(event.which === 13){
savePendingEdition($(this));
}
}
function savePendingEdition(tarefa){
console.log('...');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="todo">
<h2>TODO List</h2>
<input type="text" id="tarefa">
<div id="tarefa-lista">
<div class="tarefa-item">
<div class="tarefa-texto">Comprar pão</div>
<div class="tarefa-delete"></div>
<div class="clear"></div>
</div>
</div>
</div>
What is the function for onTarefaEditKeydown? If you are at the top input and give a tab to the created input it receives text normally, but if you click on the input it no longer receives the focus.
– LeAndrade
.keydown
does not usually work with elements dynamically created, I suggest to exchange for$(document).on('keydown', ".tarefa-edit",onTarefaEditKeydown)
. Test and inform if it worked, I could not test because there is not a testable example in your question– Ricardo Pontual