views:

26

answers:

2

Brief synopsis, this code works beautifully and does what it is supposed except with radio buttons on webkit.

$('input, textarea, select').focus(function(){
    $(this).parents('.row').addClass("hilite");
        }).blur(function(){
            $(this).parents('.row2').removeClass("hilite");
});

I did some research and tested it a few times and using

$('input, textarea, select').bind('change'(){
    $(this).parents('.row').addClass("hilite");
        }).blur(function(){
            $(this).parents('.row').removeClass("hilite");
});

I am able to get it to work with webkit radio buttons but it does not acknowledge the blur and therefor does not remove the hilite. So is there an alternate way to write this so it will remove the class on blur vs mouseleave (which does work). As always THANKS IN ADVANCE!

+1  A: 

Try giving the :radio buttons a click event to force focus. Seems to work in webkit.

Try it out: http://jsfiddle.net/5dDQn/

$(':radio').click(function() {
    $(this).focus();
});
patrick dw
That did the trick! Thank you!
CarterMan
A: 

This approach probably doesn't qualify as 'pretty' but I'd try like so:

$('input, textarea, select')
  .focus(function() {
    $(this).parents('.row').addClass('hilite');
    if ($(this).is(':radio')) {
      $(this).one('mouseleave', function () {
        $(this).parents('.row').removeClass('hilite');
      });
    }
  })
  .blur(function() {
    $(this).parents('.row2').removeClass('hilite');
  });

That relies on what I believe you indicated - the radio buttons will accept focus, don't seem to trigger blur, but mouseleave seems to work properly.

g.d.d.c
Doesn't seem like the radios get the `focus` event either. Here's the jsFiddle I posted, but without the `click` event that I added. http://jsfiddle.net/5dDQn/1/ You'll see that the `focus` doesn't fire for the radios in webkit. I agree, the question made it sound like it does fire.
patrick dw
my apologies i should have phrased it more eloquently.
CarterMan