hubrid hubrid - 2 months ago 27
jQuery Question

jQuery toggle focus

How can I toggle an element's CSS on focus/blur with jQuery?

$('.answerSpace').bind('blur', function(){
$('.normProf').toggleClass('opacProf');
});

$('.answerSpace').bind('focus', function(){
$('.opacProf').toggleClass('normProf');
});


So now I have this. But it doesn't quite work...

Answer

Try

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