[ACCEPTED]-jQuery toggle focus / blur-toggle
Accepted answer
Check this out, it's exactly how y'all should 1 do jQuery focus toggle..
Basic use case:
$('input').on('focus blur', toggleFocus);
function toggleFocus(e){
console.log(e.type)
if( e.type == 'focusin' ){
// do something on focus
}
else{
// do something else on blur
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input>
Try
$('.answerSpace').bind('blur', function(){ $('.normProf').removeClass("normProf").addClass('opacProf'); });
$('.answerSpace').bind('focus', function(){ $('.opacProf').removeClass("opacProf").addClass('normProf'); });
0
Well, if I get you right, you can use onblur and 1 onfocus events, with the toggleClass function:
$('#yourelement').bind('blur', function(){
$(this).toggleClass('your-class');
});
$('#yourelement').bind('focus', function(){
$(this).toggleClass('your-class');
});
Blur is only get active when you leave a 2 input, so you can use it to remove the focus 1 again.
$('input').focus(function(){
$(this).css('box-shadow', '0px 0px 1px #ccc');
});
$('input').blur(function(){
$(this).css('box-shadow', 'none');
});
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.