If jQuery is an option:
$("a.classbeauty").click(function(){ alert("yes link clicked"); });
If you need pure JavaScript:
var elements = document.getElementsByTagName("a"); for(var i=0; i<elements.length; i++){ if (elements[i].className == 'classbeauty') { elements[i].onclick = function(){ alert("yes link clicked!"); } } }
If you need it in Greasemonkey :
function GM_wait() { if(typeof unsafeWindow.jQuery != 'function') { window.setTimeout(wait, 100); } else { unsafeWindow.jQuery('a.classbeauty').click(function(){ alert('yes link clicked'); }); } } GM_wait();
source share