-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
  • 15,363
  • 26
  • 117
  • 213

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
  • 30,379
  • 9
  • 68
  • 99