Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/11/2012, 10:04
gebremswar
 
Fecha de Ingreso: enero-2012
Ubicación: Santiago de Surco, Lima - Perú
Mensajes: 266
Antigüedad: 12 años, 3 meses
Puntos: 57
Respuesta: Problema con children() en jQuery. No me funciona y no se cómo hacerlo.

Hola todoalbo, que tal.

Según lo que mencionas, has tener un mismo id repetido mas de una vez, en este caso id="texto". El id no se debe repetir en una pagina, debe ser único.

Prueba con clases, de la siguiente manera.


Código Javascript:
Ver original
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>@GBreagan</title>
  6. <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
  7. <script>
  8. $(document).on('ready', function() {
  9.     $('body').find('.caja').each(function(){
  10.         $(this).hover(function() {
  11.             $(this).find('a').children('.texto').stop().animate({ 'padding-bottom' : 200 }, 100);
  12.         },
  13.         function() {
  14.             $(this).find('a').children('.texto').stop().animate({ 'padding-bottom' : 10 }, 100);
  15.         });
  16.     });
  17. });
  18. </script>
  19. <style>
  20. .caja {background:#FAE078;width:200px}
  21. .texto {background:#EEEEEE}
  22. </style>
  23. </head>
  24.  
  25. <body>
  26. <div class="caja">
  27.     <a>
  28.         <img src="http://static.forosdelweb.com/customavatars/avatar452499_3.gif" height="50" width="50">
  29.         <div class="texto">Este un texto</div>
  30.     </a>
  31. </div>
  32. <div class="caja">
  33.     <a>
  34.         <img src="http://static.forosdelweb.com/customavatars/avatar452499_3.gif" height="50" width="50">
  35.         <div class="texto">Este un texto</div>
  36.     </a>
  37. </div>
  38. </body>
  39. </html>

Aunque en realidad no se mueve el texto (solo se incremente el padding de la caja que lo contiene). El problema de los selectores esta solucionado.

Saludos y coméntanos.