Return to Snippet

Revision: 9002
at October 26, 2008 18:39 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 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>');
	});
});

Revision: 9001
at October 16, 2008 22:44 by demixo


Initial Code
/*DOM Scripting*/
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>');
	}
  }  
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(mostrarMensaje);


/*jQuery*/
$(document).ready(function(){
    //Aqui asignamos el click al elemento <a>	
	$('a').click(function(){
		alert('Presionastes un elemento <a>');
	});
});

Initial URL

                                

Initial Description

                                

Initial Title
DOM Scripting vs jQuery 2: Acceso a elementos y eventos

Initial Tags
javascript, DOM, jquery

Initial Language
JavaScript