/ 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 addClass(element,value) { if (!element.className) { element.className = value; } else { newClassName = element.className; newClassName+= " "; newClassName+= value; element.className = newClassName; } } function aplicarEstilo(){ if (!document.getElementById) return false; var enlace = document.getElementById('enlace'); enlace.onclick = function(){ var parrafo = document.getElementById('parrafo'); addClass(parrafo,'resaltar'); } } addLoadEvent(aplicarEstilo); /*jQuery*/ $(document).ready(function(){ $('#enlace').click(function(){ $('#parrafo').addClass('resaltar'); }); });