Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  51] [ 5]  / answers: 1 / hits: 33463  / 12 Years ago, wed, may 9, 2012, 12:00:00

I have the following code:



HTML:



<div id='example'>
<a href='#' data-name='foo' class='example-link'>Click Me</a>
<a href='#' data-name='bar' class='example-link'>Click Me</a>
</div>


JavaScript



example_view = Backbone.View.extend({
el: $(#example),
events: {
'click .example-link' : 'example_event'
},
example_event : function(event) {
//need to get the data-name here
}
});


how can I get the data-name attribute of the link that was clicked inside of the example_event function ?


More From » jquery

 Answers
4

Try this.



example_event : function(event) {
//need to get the data-name here
var name = $(event.target).data('name');
}

[#85693] Tuesday, May 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 2 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;