I have an input field, where I try to make autocomplete suggestion. Code looks like
<input type="text" id="myinput">
<div id="myresults"></div>
On input's blur()
event I want to hide results' div:
$("#myinput").live('blur',function(){
$("#myresults").hide();
});
When I write something into my input I send request to server and get json response, parse it into ul->li structure and put this ul to my #myresults
div.
When I click to this parsed li element I want to set value from li to input and hide #myresults
div
$("#myresults ul li").live('click',function(){
$("#myinput").val($(this).html());
$("#myresults").hide();
});
Everything is going good, but when I click to my li blur()
event fires before click()
and input's value don't get li's html.
How can I set up click()
event before blur()
?
blur
is really firing after you click on anli
, then you probably don't need to execute$("#myresults").hide()
in the click handler. What it seems like is happening is that$(this).html()
is returning an empty string. Could youlog
oralert
$(this).html()
to make sure? – Trephineblur()
andclick()
handlers, there's no actions afterblur()
ends – Hegirashow()
on blur to give something to click on. Can you create the problem there? – Trephine