The code that you have would work, but is executed from the global context, which means that this refers to the global object.
You can also use the non-inline alternative, which attached to and executed from the specific element context which allows you to access the element from this.