Remove html autofocus use javascript/jquery -
here's full code:
$('input').keypress(function(e){ var code = e.keycode || e.which, value = $(this).val() if (code==13 && value!=''){ $('.with-header').show() var secondarycontent = 'secondary-content', materialicons = 'material-icons', conllectiontitem = 'collection-item' $('ul').append('<li class='+conllectiontitem+'>\ <span class="words">'+value+'</span>\ <span href="#" class='+secondarycontent+'>\ <a class="'+materialicons+' done">done</a>\ <a class="'+materialicons+' delete">delete</a>\ <a class="'+materialicons+' edit">edit</a>\ </span></li>') //this empty input $(this).val('') } }) $('body').on('click', '.done', function(){ $(this).parents('.collection-item').toggleclass('linethrough') }) $('body').on('click', '.edit', function(){ var edit = $(this).parent().prev().html('<input class="listinput">') }) $('body').on('click', '.delete', function(){ $(this).parents('.collection-item').remove() }) $('body').on('keypress','.listinput', function(e){ var code = e.keycode || e.which, value = $(this).val() if (code==13 && value!=''){ $(this).parent().html(value) } })
sorry i'm still beginner , use materialize css framework, it's kinda complicate append.
what trying making list every list can edit clicking button class '.edit' , want give autofocus list appended <input>
, autofocus work once. guess it's because put autofocus every '.listinput'.
so after append html input, , done editing list, want try remove 'autofocus' '.listinput' don't know how it?
can me or have solution? thanks
well, in case try:
$('body').on('click', '.edit', function(){ $toedit = $(this).parent().prev(); $toedit.html('<input class="listinput">') $toedit.focus(); });
Comments
Post a Comment