[ACCEPTED]-jQuery toggle focus / blur-toggle

Accepted answer
Score: 26

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>
Score: 12

Try

$('.answerSpace').bind('blur', function(){ $('.normProf').removeClass("normProf").addClass('opacProf'); });
$('.answerSpace').bind('focus', function(){ $('.opacProf').removeClass("opacProf").addClass('normProf'); });

0

Score: 7

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');
});
Score: 0

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');
});

More Related questions