I have a fiddle project here in which I want to get the clicked value for every value.full_name. But here it returns the alert for only the first value when I clicked on it. How can I return individual value?
Html:
<div id="dbg">
</div>
Javascript:
var el = $('#dbg');
var HtmlData = LoadData();
el.html(HtmlData);
function LoadData()
{
var dmJSON="http://api.railwayapi.com/route/train/12728/apikey/3dacdecg/";
var html = '<div class="row s12"/>';
$.ajax({
url: dmJSON,
dataType: 'json',
async: false,
data: {},
success: function(data) {
$.each(data.route, function(key, value) {
html += '<a id="click1" href="#menu_modal">' + '<div class="card small">' +'<div align="center" id="rest_name">' + value.fullname + "</div>" + "</div>" + '</a>' + "</div>"
});
}
});
return html;
}
$("#click1").click(
function () {
var clickedValue = $('#rest_name').text();
alert(clickedValue);
}
);
classid should be unique also usethiscontext and to now the clicked element