I have this nest of links with icon on it. When a link was clicked, the icon associated with it will changed to a loading image to shown that the link is active.
The problem is on the second click or more, the loading image won't change back to the icon and display multiple loading images.
How to make it only show one loading image and revert the previous clicked icon.
The HTML and Script
$('.parent a').click(function(a) {
a.preventDefault();
var $icons = $(this).siblings('i');
$($icons).replaceWith('<img class="active" src="https://cdn.dribbble.com/users/323893/screenshots/2077235/buffer.gif" width="30" height="30">');
$('img.active').not($icons).replaceWith('<i class="typcn typcn-thumbup"></i>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
<i class="typcn typcn-thumbup"></i>
<a href="site1">first link</a>
</div>
<div class="parent">
<i class="typcn typcn-thumbup"></i>
<a href="site2">second link</a>
</div>
<div class="parent">
<i class="typcn typcn-thumbup"></i>
<a href="site3">third link</a>
</div>
<div class="parent">
<i class="typcn typcn-thumbup"></i>
<a href="site4">forth link</a>
</div>