Okay, my question is to make a clicks or likes counter so that when someone clicks a <div>
this add the click to a <span>
anywhere in the article. This means that, if I have a new click on a photo, I put the total number of people who clicked on that photo, in the span of "I like it" without updating the page. And that I can handle it by id
s so that I can have many "likeable" photos. I have seen the odd issue about this from the outside but I have not been able to adapt it to what I need. I do not have much knowledge in PHP. And here is a basic example of my code.
$(document).ready(function(){
$(this).find(".img-hover").mouseenter(function(){
$(this).css({"background-color": "rgba(255, 255, 255, 0.5)"});
$(this).find("i").css({"color": "rgb(27, 27, 28)"});
$(this).find("i").stop().removeClass("fa-2x");
$(this).find("i").stop().addClass("fa-4x");
$(this).find("span").stop().fadeIn(200);
});
$(this).find(".img-hover").mouseleave(function(){
$(this).css({"background-color": "rgba(0, 0, 0, 0)"});
$(this).find("i").css({"color": "rgba(0, 0, 0, 0)"});
$(this).find("i").stop().removeClass("fa-4x");
$(this).find("i").stop().addClass("fa-2x");
$(this).find("span").stop().fadeOut(200);
});
$(this).find(".fa-heart").mouseenter(function(){
$(this).css({"color": "rgb(234, 96, 86)"});
});
$(this).find(".fa-heart").mouseleave(function(){
$(this).css({"color": "rgb(27, 27, 28)"});
});
});
*{
padding: 0;
margin: 0;
font-family: sans-serif;
}
.contenedor {
position: relative;
width: 250px;
height: 450px;
}
img {
max-width: 100%;
position: absolute;
}
.img-hover {
width: 100%;
height: 99%;
position: absolute;
top: 0;
left: 0;
z-index: 100;
transition: .2s;
background-color: rgba(0, 0, 0, 0);
text-align: center;
}
.fa-heart {
color: rgba(0, 0, 0, 0);
position: absolute;
top: 40%;
left: 40%;
transition: .2s;
}
.fa-heart:hover {
cursor: pointer;
}
.cuenta {
padding: 3px 8px;
background-color: rgb(247, 247, 247);
border-radius: 3px;
color: rgb(27, 27, 28);
font-size: 12px;
right: 0;
bottom: 0;
margin-right: 5px;
margin-bottom: 6px;
position: absolute;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://use.fontawesome.com/acad8e21f9.js"></script>
<div class="contenedor">
<img src="https://s-media-cache-ak0.pinimg.com/736x/0f/61/18/0f6118f167ccca50dff9e06f5b27146b.jpg" alt="img">
<div class="img-hover">
<!--Este es el "div" del click-->
<i class="fa fa-heart fa-2x"></i>
<!--Este es el "span" del resultado-->
<span class="cuenta">716</span>
</div>
</div>