I have an HTML list of links with data-…
attributes on each one:
<ul id="list">
<li><a data-info="link1"> **** </a></li>
<li><a data-info="link2">****</a></li>
<li><a data-info="link3">**** </a></li>
<li><a data-info="link4">****</a> </li>
</ul>
I need to receive the data-info
value of a link whenever it is clicked. So I thought something like this:
var my_links = $('#list').find('a');
my_links.on('click', function(){
console.log(this.data(info));
});
But then I get:
Uncaught TypeError: this.data is not a function
If I just do:
var my_links = $('#list').find('a');
my_links.on('click', function(){
console.log(this);
});
I get the complete HTML code of each link, for example:
<a data-info="link1"> **** </a>
Why are both things happening, and how can I fix it?