I have multiple images on a page. Each image has an id associated with it. For each image, I want the user to be able to click on a heart. When the user clicks on a heart, the open heart icon should be replaced by the closed heart icon for just that image. Similarly, when a user unhearts an image, the closed heart icon should get replaced by the open heart icon.
I'm having trouble implementing this in javascript correctly. How would I reference just the icon that needs to be changed? Any advice on how to implement this?
Javascript
<script >
function wantToGo(id) {
console.log(id);
}
function dontWantToGo(id) {
console.log(id);
}
</script>
HTML
<div class='col-md-4'>
<img src = "http://i.imgur.com/gwzxVWi.jpg ">
<!-- Open heart icon -->
<a href = "#" onClick = "wantToGo(4)"><i class="fa fa-heart-o"></i></a>
<!-- Closed heart icon -->
<a href = "#" onClick = "dontWantToGo(4)"><i class="fa fa-heart" aria-hidden="true" style = "color:red;"></i></a>
</div>
<div class='col-md-4'>
<img src = "http://i.imgur.com/Ohk2jxC.jpg ">
<a href = "#" onClick = "wantToGo(5)"><i class="fa fa-heart-o"></i></a>
<a href = "#" onClick = "dontWantToGo(5)"><i class="fa fa-heart" aria-hidden="true" style = "color:red;"></i></a>
</div>