Ok ora funziona in tutti e due modi:
Versione 1
codice:
function aggiungiDiv()
{
var divPrinc= document.getElementById("div1");
var img = document.createElement("img");
var divAgg= document.createElement("div");
var link=document.createElement("a");
var br=document.createElement("br");
var Tlink=document.createTextNode("Html");
img.src="prova.jpg";
img.width="80";
img.height="80";
link.href="index.html";
link.title="Prova";
link.appendChild(Tlink);
divAgg.setAttribute("class","immagine");
divAgg.appendChild(img);
divAgg.appendChild(br);
divAgg.appendChild(link);
divPrinc.appendChild(divAgg);
}
Versione 2
codice:
function aggiungiDiv()
{
divPrinc= document.getElementById("div1");
var divAgg= document.createElement("div");
var cont="<img src=\"prova.jpg\" width=\"80px\" height=\"80px\"> ";
cont=cont+"
<a href=\"index.html\" title=\"prova\">Index</a>";
divAgg.setAttribute("class","immagine");
divAgg.innerHTML=cont;
divPrinc.appendChild(divAgg);
alert('inserito');
}
Quale mi consigliate di usare e perché?