If you need to run the same function for different elements, call the name of the function, not the imoementation function:
document.getElementById("wedding").onclick = lalala; document.getElementById("divorce").onclick = lalala; //inside you can use `this` ( notice we didnt pass [this] , it is done automatically) function lalala() { this.style.position = "absolute"; this.style.left = '-450px'; this.style.top = '-260px'; this.style.zoom = 0.8; this.style.MozTransform = 'scale(0.8)'; this.style.WebkitTransform = 'scale(0.8)'; }
After cleaning the OP
var e=document.getElementById("text") document.getElementById("wedding").onclick =function (){ lalala(e) }; document.getElementById("divorce").onclick =function (){ lalala(e) }; function lalala(elm) { elm.style.position = "absolute"; elm.style.left = '-450px'; elm.style.top = '-260px'; elm.style.zoom = 0.8; elm.style.MozTransform = 'scale(0.8)'; elm.style.WebkitTransform = 'scale(0.8)'; }
source share