$('a.popup-ajax').popover({ "html": true, "content": function(){ $.ajax({ url: '/heroespage', dataType: 'json', success: function(response){ var title = $("a.popup-ajax").attr("data-heroid"); console.log(response[title]['id']); var name = response[title]['name']; var role = response[title]['role']; var img = response[title]['img']; var typeAttack = response[title]['typeAttack']; $("a.popup-ajax").attr('data-content', '<div class="hero-footnote"><img src="'+ img +'" alt=> <div class="hero-footnote__desc"><h3>'+ name +'</h3><p>'+ typeAttack+'</p><span>'+ role +'</span></div> </div>'); } }) } }); Here I take the attribute value:
var title = $("a.popup-ajax").attr("data-heroid"); id is stored there, respectively, then this id substituted in response[title] and the infa I need is displayed. All is well when the data-heroid one per page, but if there are several, then only the first value is taken. How to remake the code so that it takes the values of each element to which I impose?