View Full Version : Adding JS to FB or +1 button

08-01-2011, 09:17 AM

I was trying to add some simple javascript (toggle visibility function of a div) to the FB 'like' button and 'Google +1' button. This to simply create some more visitor interactivity by showing a thank you message for doing so.

I've tried by just adding 'onclick=' to the element that actually shows the button, with a <a href="#" onlcick="..."> --element--</a> manner, and with a <span> and a <div> element around it.

Neither of them work. The toggle script is 100% correct (using it actively with <a href="javascript:void(0);" onclick="javascript:toggleVisibility('feedbackform')">feedback</a> ) Of course I made sure the div id had correct name and it is unique for the toggle function.

Anybody got any ideas on how to go with this?


function toggleVisibility(controlId) {
if (document.getElementById) { // DOM3 = IE5, NS6
var control = document.getElementById(controlId);
if(control.style.display == "")
control.style.display = "none";
control.style.display = "";
else {
if (document.layers) { // Netscape 4
if(document.controlId.display == "")
document.controlId.display = "none";
document.controlId.display = "";
else { // IE 4
if(document.all.controlId.style.display == "")
document.all.controlId.style.display = "none";
document.all.controlId.style.display = "";

Philip M
08-01-2011, 09:43 AM
Netscape 4 and IE4 are long, long obsolete. So is onclick = "javascript:

<script type="text/javascript">
function Toggle(obj) {
var Style = document.getElementById(obj).style;
Style.display = (Style.display == "none") ? "" : "none";
<div id="MyDiv">Content Goes Here</div>

<input type = "button" value = "Toggle" onclick="Toggle('MyDiv')">

Quizmaster: The five breeds of swan found in the United Kingdom all have plumage of predominantly what colour?
Contestant: Red

08-02-2011, 12:05 AM
thanks, 100% right about that, that is a lot more efficient. However that does not solve the problem with adding extra functionality on click the 'like' button o '+1' button. I'm trying to copy the .js file from google server to my server and then add some code, however just copying the js from google server to my server and then using it does not seem to work so I'm gonna try to work around that..

08-02-2011, 09:42 AM
found a solution for what I wanted. Wrote about it here:

for anybody who is looking for the answer.

Best regards,