Search code examples
ember.jsember-cli

Reference to HTML-element that invoked an action


I'm invoking an Ember action via a link:

<a {{action "openApps"}}>Apps</a>

and handling it in the appropriate controller

actions: {
  openApps: function() {
    //...
  }
}

How do I get a reference to the <a> which invoked the action inside the controller-function.


Solution

  • It's funny. Someone answered the question yesterday with exactly what I wanted but he/she deleted the answer. Therefore here it is:

    It is perfectly possible to get the target of an action by using window.event.target:

    actions: {
      openNav: function() {
        Ember.$(window.event.target).slideToggle();
      }
    }