I’m trying to make a facebook-like-search (autocomplete), as in facebook’s/ gmail’s compose message. My whole script is at http://jsfiddle.net/6YbrP/13/.
if(e.keyCode == 8 && $(this).val() == ''){
$('#itemcontainer div.detailwrapper:last').remove();
}
With above script, when I’d like to add more items, I type some chars and erase the chars again using backspace, when the textbox clear it immediately also deleted the last element.
It’s not what I want. It shouldn’t delete the last element when the textbox clear, unless, users pressed backspace again after the textbox clear. The logic is as in facebook’s/ gmail’s compose message. SO, what should I do? Any idea to this?
Just use
keydowninstead ofkeyup.