I have an anchor (<a>
) that appears only when an <input />
is focused. The moment the <input />
is blurred, the anchor's container fades out.
I'm trying to click on the anchor to trigger the onClick()
event for it, but the moment I click, the focus changes, from the input, and the anchor's container disappears. I believe this is why when I click the anchor nothing happens.
How can I check on the blur event of the <input />
if the anchor was just clicked and that is what caused the focus to change from the <input />
and cause the blur event?
Then, if the blur event occurred because I clicked on the anchor, I can trigger the onClick()
and if not, I can fade out the anchor's container.
How can I do this javascript / jQuery ?
Update:
I am currently trying to do the following in javascript:
On blur of input, if .ss-result a
was not clicked then fade out, else alert(".ss-result a clicked!");
Here is the code that I am trying to accomplish this with, but it breaks my fading in of the anchor on focus of <input />
. I'm not getting any console errors.
var inputObj = $('input');
var boxObj = $('.container');
inputObj.blur(function() {
if($('.ss-result a').is(':focus')){
alert(".ss-result a clicked!");)
}
else{
boxObj.fadeOut(100);
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…