-1

I want to get the text of a dynamically created button but seems like i'm doing something wrong.

$(document).on('click', '.online_users', () => {
        console.log($(this).text(););
    });

1 Answers1

0

Unlike regular functions, arrow functions do not have their own this . The value of this inside an arrow function remains the same throughout the lifecycle of the function and is always bound to the value of this in the closest non-arrow parent function.

Change the arrow function to a normal function if you want to use this.

$(document).on('click', '.online_users', function () {
  console.log($(this).text())
})
madprops
  • 3,909
  • 5
  • 34
  • 42