Ciao a tutti. Mi serviva uno script show-hide e tramite una ricerca sul forum ho trovato questo. Per le mie necessità va benissimo ma mi piacerebbe che anzichè i due link mostra tutti e nascondi tutti ce ne fosse solo uno con le scritte che si alternano come per i singoli div. Qualcuno sarebbe così gentile da darmi una mano? Ciao e grazie.![]()
codice:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Documento senza titolo</title> <script type="text/javascript"> if(document.getElementById && document.createElement) { document.write('<style type="text/css">*.toggle{display:none}</style>'); window.onload=function() { /*le modifiche allo script vanno solo fatte qui*/ Attiva("nome1","mostra informazioni","nascondi informazioni"); Attiva("nome2","mostra informazioni","nascondi informazioni"); } } function Attiva(id,s1,s2) { var el=document.getElementById(id); el.style.display="none"; var c=document.createElement("div"); var link=document.createElement("a"); link.id = "a_" + id; link.href="#"; link.appendChild(document.createTextNode(s1)); link.onclick = function() { link.firstChild.nodeValue = (link.firstChild.nodeValue==s1) ? s2 : s1; el.style.display=(el.style.display=="none") ? "block" : "none"; return(false); }; c.appendChild(link); el.parentNode.insertBefore(c,el); }; function hideElements() { for (var i = 0; i < arguments.length; i++) { var e = document.getElementById(arguments[i]); e.style.display = 'none'; document.getElementById("a_" + arguments[i]).innerHTML = "mostra informazioni"; } } function showElements() { for (var i = 0; i < arguments.length; i++) { var e = document.getElementById(arguments[i]); e.style.display = 'block'; document.getElementById("a_" + arguments[i]).innerHTML = "nascondi informazioni"; } } </script> </head> <body> mostra tutti nascondi tutti <h2> Utente1</h2> <div id="nome1" class="toggle"> <dl> <dt>Nome:</dt> <dd> Mario</dd> <dt>Cognome:</dt> <dd> Rossi</dd> </dl> </div> <h2> Utente2</h2> <div id="nome2" class="toggle"> <dl> <dt>Nome:</dt> <dd> Giovanni</dd> <dt>Cognome:</dt> <dd> Verdi</dd> </dl> </div> </body> </html>

Rispondi quotando