javascript - Is there a way to get clicked element on blur or focusout event? -
this question has answer here:
how know click on blur or focusout of input?
i've sketched small example:
html:
<div id ="all"> <div id="whereisinput"> <input id="blur"/> </div> </div>
css:
#whereisinput{ height: 100px; width: 200px; background-color: yellow; }
js:
function onblur(e){ jquery('#all').append('<div>' + e.type + ', ' + e.target.tostring() + '</div>') } jquery('#blur').blur(onblur); jquery('body').on('click', onblur);
so questions is: where click when blur occured?
i've investigate this: 1. can't find in blur or focusout event arguments 2. click on body occurs later blur
you can setup flag check if blur event ocurred before click.
var blurred = false;//blur flag $(document).on("click", function(){ if(blurred){ console.log(this); blurred = false; } }); $("input#blur").on("blur", function(){ blurred = true;//blur occurred });
Comments
Post a Comment