How do I get data-id
of all links? Only the first one is coming, repeated.
[![$("#filmeItem").on("keyup focusin", function (e) {
$('.livesearchItem').fadeIn('1000');
e.preventDefault();
var busca = $('#filmeItem').val();
if (busca !== "") {
var settings = {
'async': true,
'crossDomain': true,
'url': 'https://api.themoviedb.org/3/search/movie?query=' + busca + '&api_key=9aca69849a23528a419aea463387945f&language=pt-BR',
'method': 'GET',
'headers': {},
'data': '{}'
};
$.ajax(settings).done(function (data) {
$.each(data.results, function (key, value) {
if (value.poster_path !== null) {
$('.livesearchItem').append('<a href="#" class="itn" id=' + value.id + '><div class="media"><br><div class="media-left media-middle"><img class="media-object img-thumbnail" src="https://image.tmdb.org/t/p/w92'+value.poster_path+'" width="45" height="45" alt="..."></div><div class="media-body alinhamentom"><h4 class="media-heading">' + value.title + '</h4>' + moment(value.release_date).format('Y') + '<span class="label label-success pull-right">FILME</span></div></div></a>');
} else {
$('.livesearchItem').append('<a href="#" class="itn" id=' + value.id + '><div class="media"><br><div class="media-left media-middle"><img class="media-object img-thumbnail" src="' + baseUrl + 'assets/images/img-not-found.jpg" width="45" height="45" alt="..."></div><div class="media-body alinhamentom"><h4 class="media-heading">' + value.title + '</h4>' + moment(value.release_date).format('Y') + '<span class="label label-success pull-right">FILME</span></div></div></a>');
}
});
});
}
$('.livesearchItem').empty();
});
$('.livesearchItem').on('click', function () {
console.log($('.itn').attr('id'));][1]][1]
** Update: **. I solved the problem by using the "dataset"