Consider this example where I have 2 input fields:
<input id="a" />
<input id="b" style="display: none" />
And consider the following JavaScript, which is an attempt to do this:
Show #b
only when #a
has focus and hide #b
whenever #a
loses focus, except when #a
loses its focus to #b
.
$("#a").focus(function() {
$("#b").show();
});
$("#a, #b").blur(function() {
$("#b").hide();
});
$("#b").focus(function(){
$("#b").show();
});
$("#a").focus(function() {
$("#b").show();
});
$("#a, #b").blur(function() {
$("#b").hide();
});
$("#b").focus(function() {
$("#b").show();
});
#b {
display: none;
}
<input id="a" value=a>
<input id="b" value=b>
<br/>^ focus on the input
See Question&Answers more detail:os