Return to Snippet

Revision: 9056
at October 26, 2008 18:40 by demixo


Updated Code
/*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');
	});
});

Revision: 9055
at October 20, 2008 09:24 by demixo


Updated Code
/*DOM Scripting*/
function aplicarEstilo(){
  if (!document.getElementById) return false;
  var enlace = document.getElementById('enlace');
  enlace.onclick = function(){
	var parrafo = document.getElementById('parrafo');
	addClass(parrafo,'resaltar');
  }
}
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(aplicarEstilo);


/*jQuery*/
$(document).ready(function(){
	$('#enlace').click(function(){
		$('#parrafo').addClass('resaltar');
	});
});

Revision: 9054
at October 20, 2008 08:07 by demixo


Updated Code
/*DOM Scripting*/


/*jQuery*/
$(document).ready(function(){
	$('#enlace').click(function(){
		$('#parrafo').addClass('resaltar');
	});
});

Revision: 9053
at October 20, 2008 08:03 by demixo


Updated Code
/*DOM Scripting*/


/*jQuery*/
$(document).ready(function(){
	$('a').click(function(){
		$('p').addClass('resaltar');
	});
});
$("a").addClass("resaltar");

Revision: 9052
at October 20, 2008 07:45 by demixo


Initial Code
/*DOM Scripting*/

addClass('a',"resaltar");

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

/*jQuery*/
$("a").addClass("resaltar");

Initial URL

                                

Initial Description

                                

Initial Title
DOM Scripting vs jQuery 3: Añadir una clase

Initial Tags
javascript, DOM, jquery

Initial Language
JavaScript