Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/03/2013, 07:32
Avatar de chuidiang
chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 20 años, 5 meses
Puntos: 454
Respuesta: Cambiar clase "active" a elemento seleccionado

Hola:

He copiado tu código todo junto, he añadido un style para ver el cambio y parece que funciona bien, el puntito de delante de los <li> se cambia de color

Código HTML:
Ver original
  1.    <head>
  2.       <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  3.       <style>
  4.          .active {
  5.             color:red;
  6.          }
  7.       </style>
  8.    </head>
  9.    <body>
  10.       <script>
  11.       $(function() {
  12.        $('.nav li a').click(function(e) {
  13.            e.preventDefault();
  14.            var $this = $(this);
  15.            $this.closest('ul').children('li').removeClass('active');
  16.            $this.parent().addClass('active');
  17.        });
  18.       });
  19.    </script>
  20.    <ul class="nav">
  21.      <li class="active"><a href="#">Enlace 1</a></li>
  22.      <li><a href="#">Enlace 2</a></li>
  23.      <li><a href="#">Enlace 3</a></li>
  24.    </ul>
  25. </body>
  26. </html>

Se bueno.
__________________
Apuntes Java
Wiki de Programación