Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs - Get attribute of element clicked

Tags:

ember.js

Question: Upon click, I see that evt.target.attributes stores all of the attributes in an array. Is there an easier way without having to iterate all of the attributes to get a certain attributes value? In this example I need the value of the 'note' attribute for the element clicked.

Template:

<a note="C" {{action "play" on="click"}}>></a>

Click handler(play):

var keys = Ember.View.create({
    templateName: 'keys',
    notes: this.get('allKeys'),
    play:function(evt){
        var attributes= evt.target.attributes;
        console.log(attributes);
    }
like image 505
Fostah Avatar asked Dec 03 '25 02:12

Fostah


1 Answers

If a controller isn't backing the view, one solution is to turn the event target into a jQuery object

play : function(event) {
    var note = $(event.target).attr("note");
    // More code here
}
like image 146
PastryExplosion Avatar answered Dec 05 '25 19:12

PastryExplosion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!