for example here i have three icon (fa fa-heart),Normally icon color is green, My requirement is,if icon 2 is clicked, the background color should change red using an onclick event. suppose again i am clicking same icon 2 means background color should change in green, after that i am clicking icon 3 means background color should change red, I have tried but I am not able to do this. i am getting answer like this, If I click icon 2, icon 1 color is changing. If I click icon 3 , icon 1 color is changing. like every time icon 1 is changing color
<div class = "col-md-8 top-a rentListing"> </div>
function searchLocality() {
var city = "something";
var locality = "something";
$.ajax({
type: "POST",
data: {
city: city,
locality: locality
},
url: "rentlocalityFilter.php",
success: function(data) {
var htmlString = '';
$.each(res['data'], function(key, value) {
var id = value.id;
htmlString += '<a class="col-md-1 icon" style="margin-top:10px;cursor:pointer" onclick="guesttt_login()"><i class="fa fa-heart" aria-hidden="true" style="margin-top: -11px; color: green;" id="button" onclick="setColor(' + value.id + ')"></i></a>';
});
$('.rentListing').empty().append(htmlString);
}
});
}
var count = 1;
function setColor(id) {
var btn = 'button';
var color = '#101010';
var property = document.getElementById(btn);
if (count == 0) {
property.style.backgroundColor = "green"
count = 1;
} else {
property.style.backgroundColor = "red"
count = 0;
}
}