First, why this is a bad idea:
- Like Gates are no longer allowed, check out the changelog and the platform policy
- It is annoying for the user if he can´t unlike something directly where he liked it.
- Users can´t comment on the like button if you hide it right after clicking
- Sometimes it needs confirmation to like something (for spam reasons, for example) - if you hide the button after clicking, the user can´t confirm and the like will not get through
- It´s pointless anyway, because you will not be able to detect it for returning users so you would need to show the like button every time you refresh the page. You may use a cookie, but that´s not really a reliable solution.
...and please don´t try to solve the most simple things with jQuery. Instead of jQuery.appendTo
, you can use appendChild
, innerHTML
, ... Learn JavaScript before using a library for it, or you will end up using it for everything - which is usually a lot slower than Vanilla JavaScript and not even less code in many cases.
That being said, it´s not that simple to hide it, you would need to use FB.Event.subscribe to subscribe to the like event: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.2
See this thread, for example: Attach a click() event to the FaceBook 'Like' button?
And again, because it´s very important: Like Gates are not allowed!