é possibile utilizzare i comandi di ricerca avanzata per rendere la ricerca globale e/o case sensitive


recuperare elementi

.getElementById("...")
individua elementi con un ID


.getElementsByTagName("...")
individua elementi con un specifico tag HTML e restituisce un array di questi elementi

si usano quindi tutti i metodi dell'array:


esempio: individua gli aelementi e ne cambia il colore in base ad un array
colore = new Array("red","orange","green");

function colore_celle()
{

if(document.getElementById && document.getElementsByTagName) per cross-browsing
{
celle = document.getElementById("r3").getElementsByTagName("td");

for(i=0; i < celle.length; i++)
celle.item(i).style.color = colore[i];
}
}




creare elementi


.createElement()
creare un nuovo elemento di qualunque tipo

nuovo_elemento = document.createElement("tipo_TAG")

esempio:
function inserisci_immagine(){

if(document.getElementById && document.createElement){
immagine = document.createElement("IMG");
immagine.setAttribute("src","Logo.gif");
immagine.setAttribute("alt","Esempio");

document.getElementById("par_pre").appendChild(immagine);}
}




.createTextNode()
permette di creare un nuovo nodo di testo

nuovo_testo = document.createTextNode("testo_da_inserire")

esempio:
function inserisci_frase(){

if(document.getElementById && document.createTextNode){
frase = document.createTextNode("Iniziamo con un esempio semplice");

document.getElementById("par_pre").appendChild(frase);}
}




.innerHTML
si può usare anche il comando .innerHTML per creare ed inseire elementi/testi/nodi
vedi comandi analisi ed elaborazione

attenzione: cancella tutti gli elementi/testi/nodi precedenti


.tagName

restituisce il nome del tag dell'elemento associato

elemento_recuperato.tagName