document.getElementById e document.getElementsByTagName + ciclo for

« Older   Newer »
  Share  
max_400
view post Posted on 5/4/2012, 02:08     +1   -1




document.getElementById e document.getElementsByTagName + ciclo for
oltre a dare un azione ad un indentificatore ID lo possiamo fare anche con il nome del tag

tagname
controllare i bordi

CODICE
<style>
.banana{
border: 5px solid #ff0000;
width: 200px;
}
</style>

<script>
function bordo(){
document.getElementById('bersaglio').className='banana';
}
</script>

--------------Questo con getElementByID---------------------------<br>
<p id="bersaglio">hhhhhh</p>

<input type="button" onclick="bordo()" value="bordo">
<input type="button" onclick="location.reload()" value="togli bordo"><br>


---------oppure tutti i paragrafi con contorno-----con--document....tagName--------------<br>

<script>
function bordi(){
totale=5;
i=0;
for(i=0;i<=totale;i++){
document.getElementsByTagName('p').item(i).className='banana';
}
}
</script>

<p>aaa</p>
<p>bbb</p>
<p>ccc</p>

<input type="button" onclick="bordi()" value="bordi">
<input type="button" onclick="location.reload()" value="togli bordo"><br>



Ed ecco l'esempio
http://max400.netne.net/document_get_Eleme..._e_tagName.html

PS per sbrigarmi prima ho usato il reload... ih ih ih

 
Top
0 replies since 5/4/2012, 02:08   100 views
  Share