Solució Exercici 6 - 2009-NOV-04

<html>
<head>
<title>Escriure un text dins d'un paràgraf</title>
<script>
//Mode 1 - Fent servir innerText o innerHTML
function escriure(p) {
document.getElementById(p).innerHTML ="Hola ¿Cómo estás?";
}

//Mode 2 - Fent servir el DOM
function escriure2(p) {
var texto="Patates fregides."
document.getElementById(p).firstChild.nodeValue=texto;
}

//Mireu l'adreça:

http://www.alfonsojimenez.com/computers/no-uses-innerhtml-usa-do

m



</script>


</head>
<body>
<a href="#" onclick="escriure('parag');">Clica i veuràs.</a> |
<a href="#" onclick="escriure2('parag');">Una altra opció</a>

<p id="parag"> </p>

</body>
</html>

0 comentarios: