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(););
});
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(););
});
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())
})