My Json format is as follows:
[{"id":"1","Text":"esj","DateTime":"2015-10-21 19:00:00", "Color":"Red"},
{"id":"1","Text":"esj","DateTime":"2015-10-21 19:00:00", "Color":"Red"},
{"id":"1","Text":"esj","DateTime":"2015-10-21 19:00:00", "Color":"Red"},
{"id":"1","Text":"esj","DateTime":"2015-10-21 19:00:00", "Color":"Red"}]
I also have a jquery script in which I'm adding dinamically hyperlinks:
$.ajax({
url: './download.php',
type: "POST",
data: {
id: id
},
dataType:'text',
success: function(ans)
{
var data = JSON.parse(ans);
$.each(data, function(i, v) {
$('links').append('<li><a><div>' + v.Text + '<span class="small">' + v.DateTime+ '</span></div></a></li>');
});
}});
I want a simple effect - a list of hyperlinks on my webpage. When user cliks any hyperlink, he will see an alert window with the value of the field id
, Color
, DateTime
and Text
.
I tried adding a function inside $.each:
$.find('a').click(function(){
alert(v.Color+v.id+v.Date+v.Text);
})
But it tells me:
Uncaught TypeError: $.find(...).click is not a function
So how can I append a function (click handler) to each generated link that will be displaying all properties related to the clicked link?