Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Callback Scope

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?

like image 317
anon Avatar asked Nov 26 '25 00:11

anon


1 Answers

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());
        }
    }
}
like image 62
Darin Dimitrov Avatar answered Nov 27 '25 15:11

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!