JQuery callback scope

Suppose I have this code

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

How to access the value of checkboxes? $ (this) doesn't work, since you are currently in a hidden element?

+3
source share
1 answer

You can commit the value in an external function:

$(document).ready(function() {
    $('.checkbox').change(function() {
        var $checkbox = $(this);
        $('.hidden').slideUp('slow', function() {
            alert($checkbox.val());
        }
    }
}
+6
source

Source: https://habr.com/ru/post/1721957/


All Articles