-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
  • 13,972
  • 24
  • 98
  • 190

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
  • 26,049
  • 8
  • 51
  • 86