TypeScript: Using jquery $(this) in event

According to Typescript’s spec “this” is referring to the instance of class the method belongs to/is called on.

You could use the target attribute of the event object passed to the callback:

class foo {
  public test(evt){
    alert($(evt.target).data("id")); // "undefined"
    console.log($(evt.target));
  }
}

Or event.currentTarget depending on if you want to get the element actually clicked on or the element which captured the event.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)