onblur

jQuery: fire click() before blur() event

↘锁芯ラ 提交于 2019-11-26 19:27:23
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()); $

How to blur the div element?

雨燕双飞 提交于 2019-11-26 16:37:43
I have a dropdown menu inside a DIV. I want the dropdown to be hide when user click anywhere else. $('div').blur(function() { $(this).hide(); } is not working. I know .blur works only with <a> but in this case what is the simplest solution? djch I think the issue is that divs don't fire the onfocusout event. You'll need to capture click events on the body and then work out if the target was then menu div. If it wasn't, then the user has clicked elsewhere and the div needs to be hidden. <head> <script> $(document).ready(function(){ $("body").click(function(e) { if(e.target.id !== 'menu'){ $("

How to use onBlur event on Angular2?

北城以北 提交于 2019-11-26 15:56:44
问题 How do you detect an onBlur event in Angular2? I want to use it with <input type="text"> Can anyone help me understand how to use it? 回答1: Use (eventName) for while binding event to DOM, basically () is used for event binding. Also use ngModel to get two way binding for myModel variable. Markup <input type="text" [(ngModel)]="myModel" (blur)="onBlurMethod()"> Code export class AppComponent { myModel: any; constructor(){ this.myModel = '123'; } onBlurMethod(){ alert(this.myModel) } } Demo

Get the clicked object that triggered jquery blur() event [duplicate]

旧城冷巷雨未停 提交于 2019-11-26 09:44:19
问题 This question already has answers here : When a 'blur' event occurs, how can I find out which element focus went *to*? (23 answers) Closed 5 years ago . Suppose I do this: $(target).blur(function(e){ //do stuff }); Is there a way to fetch the object that was clicked on in order to trigger the blur action? I tried using e.target , but that appears to be returning the object attached to the blur action rather than the clicked object. 回答1: If I understand your question correctly, this should do

How to blur the div element?

不打扰是莪最后的温柔 提交于 2019-11-26 04:51:35
问题 I have a dropdown menu inside a DIV. I want the dropdown to be hide when user click anywhere else. $(\'div\').blur(function() { $(this).hide(); } is not working. I know .blur works only with <a> but in this case what is the simplest solution? 回答1: I think the issue is that divs don't fire the onfocusout event. You'll need to capture click events on the body and then work out if the target was then menu div. If it wasn't, then the user has clicked elsewhere and the div needs to be hidden.