[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){

    if( e.type == 'focusin' ){ 
      // do something on focus
      // do something else on blur
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Score: 12


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


Score: 7

Well, if I get you right, you can use onblur and 1 onfocus events, with the toggleClass function:

$('#yourelement').bind('blur', function(){

$('#yourelement').bind('focus', function(){
Score: 0

Blur is only get active when you leave a 2 input, so you can use it to remove the focus 1 again.

    $(this).css('box-shadow', '0px 0px 1px #ccc');

    $(this).css('box-shadow', 'none');

More Related questions