Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script language="JavaScript"> function muestra_oculta(id) { if (document.getElementById) { //se obtiene el id var el = document.getElementById(id); //se define la variable "el" igual a nuestro div alert(el); el.style.display = (el.style.display == 'none') ? 'block' : 'none'; //damos un atributo display:none que oculta el div } } window.onload = function() { /*hace que se cargue la función lo que predetermina que div estará oculto hasta llamar a la función nuevamente*/ muestra_oculta('contenido_a_mostrar');/* "contenido_a_mostrar" es el nombre que le dimos al DIV */ } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title> </head> <body> <?php for($i=1; $i<=2; $i++) { ?> <!--Al hace llamado a la función solo tienes que idicar el nombre del DIV entre parentesis --> <p><a style='cursor: pointer;' onclick="muestra_oculta('<?php echo "contenido_a_mostrar".$i?>')" title="">Mostrar / Ocultar</a></p> <div id="<?php echo "contenido_a_mostrar".$i?>"> <p>Este contenido tiene que mostrarse con el link</p> </div> <?php } ?> </body> </html>