I have a problem by handling focus on/off on a toggle button. If I click on the button the focus goes on and also appear the container, so it works good. If I re-click on the button the container disappear but the focus still remain with focus on! The only solution is click outside the button to focus off and this is very bad. So I would like: focus visible when the container appear (click on button) and focus off when the container disappear (re-click on button). How can I fix it? here fiddle: https://jsfiddle.net/vo1npqdx/802/ as you can see when re-click the button, the container disappear but blue color (focus on) remain, so the button doesn't come back to the original color in automatic.
css:
.ini{
color: red;
border: 2px solid #0000FF;
}
.ini:hover, .ini:focus{
color: blue;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.175);
}
js:
$("#chi").hide();
$("#hs1").click(function(){
if($('#chi').is(':hidden')){
$("#chi").toggle(500);}
else{$("#chi").hide(1000);}
});
html:
<a class="btn btn-default ini" id="hs1" href="#" role="button">TEST</a>
<div class="container" id="chi">
<div class="row">
<div class="col-xs-11 col-sm-12 col-md-10 col-lg-8 col-centered">
<div class="panel panel-primary">
<div class="panel-heading"><h2>Test</h2><h5>Test</h5></div>
<div class="panel-body">
<p>Test</p>
</div>
</div>
</div>
</div>
</div>