How to get the element from a jQuery on() event using an ES6 arrow function?


This question already has an answer here:


You can use event.currentTarget to refer to the target element of the handler

$(document).on('click', '.inserted-el', function(event) {
  snippet.log('old -> ' + this.innerHTML + ':' + event.currentTarget.innerHTML);
$(document).on('click', '.inserted-el', (event) => {
  snippet.log('new -> ' + this.innerHTML + ':' + event.currentTarget.innerHTML);
<!-- Provides the `snippet` object, see -->
<script src=""></script>
<script src=""></script>
<button class="inserted-el">1</button>
<button class="inserted-el">2</button>


is your friend here.

The reason you can't access it as 'this' is because arrow functions have the same 'this' as their parent scope.

You should also know about

Need Your Help

passing multiple values using GTK_SIGNAL_FUNC

c gtk

I'm trying to pass multiple values to a function when gtk_button click event invoke. The value are type of struct, int and gtk_image. I have a set of gtk images which attached to a table. The code

Extracting Table Data with JSoup on Yahoo Finance

java html-parsing jsoup

Trying to practice extracting data from tables using JSoup. Can't figure out why I can't pull the "Shares Outstanding" field from