I'm having an issue understanding how I might go about using the this
keyword to refer to a DOM element that is has been clicked, but also using that inside a class where this
usually refers to the instance of that class.
Here's a snippet of the relevant code:
class Passwords {
constructor() {
$('.password-column button.steel-button').on('click', this.selectButton);
}
selectButton() {
$(this).toggleClass('selected');
this.columnController();
}
columnController(){
// A function that does something else
}
}
The issue I'm having is that it doesn't recognize columnController()
as a function.
I imagine this is because of the scope and how it works with 'this', but I'm not sure how to proceed.
In the above code, selectButton()
is successfully applied to all the buttons specified, but the error is given on this.columnController()
.
Exact console error is:
Uncaught TypeError: this.columnController is not a function
Thank you in advance.