/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/*DOM Scripting*/ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } function mostrarMensaje(){ if (!document.getElementsByTagName) return false; var links = document.getElementsByTagName('a'); for (var i=0;i<links.length;i++) { links[i].onclick = function() { alert('Presionastes un elemento <a>'); } } } addLoadEvent(mostrarMensaje); /*jQuery*/ $(document).ready(function(){ //Aqui asignamos el click al elemento <a> $('a').click(function(){ alert('Presionastes un elemento <a>'); }); });