3

Lets say I have this code

$(document).ready(function()
{
   $('.checkbox').change(function()
   {
      $('.hidden').slideUp('slow', function()
      {
         alert(checkbox value);
      }
   }
}

How do I access the checkboxes value? $(this) doesn't work as you're now in the .hidden element?

1 Answer 1

6

You could capture the value in the outer function:

$(document).ready(function() {
    $('.checkbox').change(function() {
        var $checkbox = $(this);
        $('.hidden').slideUp('slow', function() {
            alert($checkbox.val());
        }
    }
}
2
  • Well, that was easier than I expected... How would I then go about converting $checkbox to a jQuery object so I can get access to .attr() ?
    – anon
    Commented Nov 5, 2009 at 7:25
  • @Matt, I've updated my sample to capture the jQuery element instead of the native one. Commented Nov 5, 2009 at 13:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.