this is my code
html :
<input type="text" class="js-input">
<div class="js-autofill"></div>
jquery :
var myarray = ['apple' , 'orange'];
myarray.forEach(element => {
$('.js-autofill').append(
`<div class="js-item" data-value="`+element+`">` +element+ `</div>`
)
})
$(document).on('click','.js-item',function(){
$('.js-input').val($(this).attr('data-value'))
})
problem is .js-item onclick not working at firsttime - it's work when i doubleclick
i can't find why