-1

If parent is a jQuery element, when I do this:

parent.change(function (e) {
    e.preventDefault();
    console.log($(this));
    console.log($(this).data('tab'));
});

This is working, but when I do this:

parent.change((e) => {
    e.preventDefault();
    console.log($(this));
    console.log($(this).data('tab'));
});

it's not working, why?

Olivier Pons
  • 14,839
  • 25
  • 109
  • 203

1 Answers1

1

The this keyword get a different context within arrow functions.
Try this instead:

parent.change((e) => {
    e.preventDefault();
    console.log($(e.target));
    console.log($(e.target).data('tab'));
});
Sagiv b.g
  • 28,620
  • 8
  • 59
  • 91