I have this simple table containing user details (user id in the provided example). There's a link available for each record. This link (in real) is dynamically generated based on no.of records. each record will have a link. And upon clicking this link, that corresponding user's id has to be passed (appended) to another link (which I refer as user link in the example).
My HTML Code:
<a id="abc" href="aa/">User Link</a>
<hr>
<table border="1">
<tr>
<td><a id="xyz" data-userid="100" href="#">first user</a></td>
<td>100</td>
</tr>
<tr>
<td><a id="xyz" data-userid="200" href="#">second user</a></td>
<td>200</td>
</tr>
<tr>
<td><a id="xyz" data-userid="300" href="#">third user</a></td>
<td>300</td>
</tr>
</table>
jQuery:
$(document).on('click','#xyz',function(e){
var uid = $(this).attr('data-userid');
$('#abc').attr('href',$('#abc').attr('href')+uid);
});
I am appending the user id to the User Link based on the above jQuery code.
This is what I am trying to achieve:
<a id="abc" href="aa/100">User Link</a>
for first user
<a id="abc" href="aa/200">User Link</a>
for second user
<a id="abc" href="aa/300">User Link</a>
for third user
which I get partially.
Issue:
When I click a second link after clicking a previous one, both the values are appending to the end of User Link.
For example, If I click first user initially, User Link becomes
<a id="abc" href="aa/100">User Link</a>
and then if I click second user, User Link becomes
<a id="abc" href="aa/100200">User Link</a>
and so on...which is not what I am trying to get. Where did I make mistake???
P.S: use Inspect Element from browser to see this mess in live action.