views:

25

answers:

1

Here's the, stripped down, code:

$(document).ready(function()
{
   var $input = $('input[type="checkbox"]');

   $input.wrap('<div class="stylecheck-container" style="display: inline" />').addClass('stylecheck').hide();
   $container = $input.parent('div.stylecheck-container');

   if ($container.parent('label').length > 0)
   {
      $container.append($container.parent('label').text() + ' ');
      $container.parent('label').replaceWith($container);
   }

   $input.change(function()
   {
      alert(1);
   });

   $container.click(function()
   {
      if ($input.is(':checkbox'))
      {
         if ($input.is(':checked'))
            $input.attr('checked', true);
         else
            $input.attr('checked', false);
      }
   });
}); 

The problem I'm having is that when I try and remove the parent label, the change no longer gets detected.

If I comment out the line 6 if statement, it works fine.

What's the deal?

A: 

Worth a shot but have you tried replacing $input.attr('checked', false); with $input.removeAttr('checked'); ? Because you're still setting it.

Though I'm very sleepy so I haven't properly parsed all the code, but I see this little thing.. off to sleep.

meder
Just tried it then - Didn't fix it. I can't see why removing the label would cause the code to fail :/
Greg