0

The title says it all. When you click like on Facebook, it shows liked and increments the like counter without refreshing the whole page. How it works?

Affan
  • 25
  • 6
  • 3
    Possible duplicate of [How does the Facebook Like button work?](https://stackoverflow.com/questions/8256083/how-does-the-facebook-like-button-work) – Harsh Gundecha Oct 20 '17 at 05:18
  • @HarshGundecha The answer explains about who widget of Facebook like button work on external site. I want to know how the like counter is incremented dynamically without refreshing the whole page. – Affan Oct 20 '17 at 05:23

2 Answers2

1

Facebook uses a Javascript framework/library/whatever you want to call it called React, in fact Facebook are the creators / maintainers of React.

What happens is when you click the like button, a javascript variable in the facebook application state gets updated by adding 1 to it. The element is then updated with this new value. It's fairly straight forward stuff, in fact There's even a demo for something similar on the React Redux github page.

Jhecht
  • 4,407
  • 1
  • 26
  • 44
0

Mostly it uses javascript or some framework of javascript. See example. Example gets the current count and if you click the like button it increments by one.

$(".like").click(function () {
    var counter = $(".likecounter").text();
    counter = parseInt(counter);
  counter = counter+1;
    $(".likecounter").html(counter);
});
CtrlAltElite
  • 28
  • 1
  • 5