19 - Recuperar un atributo de un elemento (getAttribute)


Disponer dos enlaces a distintos sitios. Recuperar la propiedad href del primer enlace y fijar el segundo enlace con dicho valor.
<html>
<head>
<title>Problema</title>
<script language="javascript" src="funciones.js" type="text/javascript"></script>
</head>
<body>
<a id="enlace1" href="http://www.google.com.ar">Google.</a><br>
<a id="enlace2" href="http://www.msn.com">MSN.</a><br>
<input type="button" value="Recuperar atributo href del primer 
enlace y copiarlo al segundo" onClick="recuperarAtributo()">
<br>
</body>
</html>
function recuperarAtributo()
{
  var puntero1=document.getElementById('enlace1');
  var puntero2=document.getElementById('enlace2');
  puntero2.setAttribute('href',puntero1.getAttribute('href'));
}

Ver solución
pagina1.html



funciones.js