leaflet :receive value onclick event on marker.binbdpopup each time

leaflet :receive value onclick event on marker.binbdpopup each time

I have an issue receiving data from my hyperlink to my on click function after bindpopup. Let me explain. First i receive a two dimensional array (data) from a json file .This array has lat and lng of markers plus some usernames which i want to put to the popups. So what i do is make a for loop for the markers to be added on the map , then bind the popups with them. This works. Now i want each popup to have a hyperlink inside ,each with a different name (that works too) and then when a user clicks on the hyperlink , i want the value of the hyperlink to be transefered in the onlick function.I make it as clear as possible. In my code below everything works as expected except that if i click another hyperlink after i clicked one , i dont get the correct value .Instead i get what i got at the first click. It always show's the first's click value. How can i make it work for every popup? (If you have any question dont hesitate to comment) This issue have blocked my project for days and its not a for loop closure issue.(the [0] at the end of the bindpopup is a DOM node for the popup to work properly!) I cant use for loop closure , i dont know how. I read everything and tried the solutions but there is a [0] DOM node at the end. How can i pass variable with that blocking me ? Also i understand that [0] selects only the first element thats why the on 'click' function works only for the first click. I am confused with all these . 

This is the code : 
$.getJSON("homesearchplayers.php", function(data) { for (var i = 0; i < data.lat.length; i++) { var player = new L.marker([data.lat[i],data.lng[i]]).addTo(mymap); player.bindPopup($('<a id="show-profile" href="#">'+data.inname[i]+'</a>').click(function(){ document.getElementById("dialog").title = $(this).text() + "'s profile :"; $('#dialog').dialog(); })[0]); } });
 <div id="dialog" title="Basic dialog" style="display:none;">
 <p id="dialog-text">inside text</p> </div>