Ir para conteúdo
Fórum Script Brasil
  • 0

Como manipular um id que foi gerado dinamicamente(PHP/Jquery)


Guest Eldes da Silva

Pergunta

Guest Eldes da Silva

Bom dia a todos

Desculpem a minha ignorancia e falta de experiencia estou começando agora !!

estou puxando informações do banco de dados e imprimindo tudo isso em uma tabela enquanto houver informação do banco !!

dentro das celulas dessas tabelastenho algumas divs que estou gerando um id dinamicamente para elas !!!

gostaria de saber como manipular esses ids desass divs criados dinamicamente !!!

Por favor me ajudem estou a muito tempo tentando resolver este problema, já procurei na net mais na achei nada !!

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0
Guest Eldes da silva

Vou dar um exemplo de como funciona o codigo

&lt;script type="text/javascript" src="javascript/jquery.js"></script>
           &lt;script>
                       $().ready(function() {
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                       
                       
                           $("#a").click(function(){ 
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                                                
                           $('#1').show("slow");
                           $('#12').show("slow");                                      
                       });
                            $("#b").click(function(){           
                       
                       $('#1').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                      
                           $('#2').show("slow");
                           $('#13').show("slow");                                      
                       });    
                            $("#c").click(function(){           
                        $('#1').hide();
                        $('#2').hide();
                         $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#13').hide();
                        $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                      
                           $('#3').show("slow");
                           $('#14').show("slow");                                      
                       });    
                            $("#d").click(function(){           
                      
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                       
                           $('#4').show("slow");
                           $('#15').show("slow");                                      
                       });    
                            $("#e").click(function(){           
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                        $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                      
                           $('#5').show("slow");
                           $('#16').show("slow");                                      
                       });    
                            $("#f").click(function(){           
                      
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#7').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                        $('#18').hide();
                       $('#19').hide();
                       $('#20').hide();
                           $('#6').show("slow");
                           $('#17').show("slow");                                      
                       });    
                            $("#g").click(function(){           
                      
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#8').hide();
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#19').hide();
                       $('#20').hide();
                           $('#7').show("slow");
                           $('#18').show("slow");                                      
                       });    
                            $("#h").click(function(){  
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();            
                       $('#9').hide();
                       $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                           $('#8').show("slow");
                           $('#19').show("slow");                                      
                       });    
                            $("#i").click(function(){           
                       $('#1').hide();
                       $('#2').hide();
                       $('#3').hide();
                       $('#4').hide();
                       $('#5').hide();
                       $('#6').hide();
                       $('#7').hide();
                       $('#8').hide();
                        $('#12').hide();
                       $('#13').hide();
                       $('#14').hide();
                       $('#15').hide();
                       $('#16').hide();
                       $('#17').hide();
                       $('#18').hide();
                       $('#19').hide();
                           $('#9').show("slow");
                           $('#20').show("slow");                                      
                       });    
                                                                                  
                            
                              });  
    </script> 








<?

 $x = 1;
   $y = a;
   $z = 12;

?>

     <table align='center' border="0" cellpadding='0' cellspacing='4' bordercolor='#ffffff' bgcolor='#cccccc'>
                            
                          <tr>
                          
                                <td><p><font face='Verdana, Arial, Helvetica, sans-serif' size='2'><b>Usuário do <? echo $db1->f("server_nome"); ?></b></font></p></td>
                              <td><b>Ultimo Login</b><br> <? echo $dia1; ?>/<? echo $mes1; ?>/<? echo $ano1; ?> Hora <? echo $hor1; ?>:<? echo $mim1; ?> seg <? echo $seg1; ?>   </td>
                              <td><b>Ultimo Acesso</b><br> <? echo $dia; ?>/<? echo $mes; ?>/<? echo $ano; ?> Hora <? echo $hor; ?>:<? echo $mim; ?> seg <? echo $seg; ?></td>                     
                            </tr> 
<?

              $db3 = new DB_Cyphor;
                  $db3->connect();
                        $query3="SELECT DISTINCT (crc.parent), cr.fullname, cr.shortname, gr.name,cr.id AS curso_id,cr.visible FROM mdl_course_categories crc
                                           LEFT JOIN mdl_course cr ON cr.category = crc.id
                                           LEFT JOIN mdl_groups_courses_groups gcg ON gcg.courseid = cr.id
                                           LEFT JOIN mdl_groups gr ON gcg.groupid = gr.id
                                              WHERE gcg.groupid IN (SELECT grp.id FROM mdl_groups grp
                                                                     LEFT JOIN mdl_groups_members grpm ON grpm.groupid = grp.id
                                                                               WHERE grpm.userid='$userid')"; 
                     $result3 = mysql_query($query3,$dbh);
                       $nrs3 = mysql_num_rows($result3);  

  while($ln3 = mysql_fetch_array($result3)) {   

              $j++;
                     
                     if($j % 2==0 ? $bgcolor = "#CFCFCF": $bgcolor = "#E0EEEE")

                            
                         
                          
                    
                     $course_id= $ln3['curso_id']; 
                     $visible = $ln3['visible'];  
                     if($visible==0){
                     
                     $text_ini ='#FF4040';
                     
                     }if($visible==1){
                     
                     $text_ini='#000000';
                     ?>


                           <tr bgcolor='<? echo $bgcolor;?>'>
                            <td ><font color='<? echo $text_ini;?>'><a href='#' id='<? echo $y; ?>'><? echo $ln3['fullname']; ?></a><? if($visible==0){echo '(Sala Inibida!)';   }?></font></td>
                            <td ><font color='<? echo $text_ini;?>'><? echo $ln3['shortname']; ?></font></td>
                            <td ><div id='<? echo $x; ?>'><table><tr><td>


<?
                        $x++;
                         $y++;
                         $z++;

}
echo "</table>";

Eu queria saber se tem uma forma mais facil de identificar as minhas DIV e depois poder manipular elas com JQUERY !!!

Se alguém puder me aJudar eu agradeceria muitoooo !!!!

Por favorrrrrrrrrr!!!!

Link para o comentário
Compartilhar em outros sites

  • 0

É só você fazer algo como isso aqui:

<script type="text/javascript">
div_id = "<? echo $x; ?>"
x = document.getElementById(div_id)
</script>

Se funcionar posta aí, pode ajudar outras pessoas com o mesmo problema

Editado por Jonathan Queiroz
Link para o comentário
Compartilhar em outros sites

  • 0
Guest Eldes da Silva

Muito obrigado pela atenção!!

Maiss

Eu tentei do jeito que você falou e não deu certoo!!!

Por favorrrr alguennnn me de uma luz !!!

Porrrrrrrrr Faaaaaavorrrrrrrrr

Eu sei que deve seu alguma coisa boba , mais eu gostaria de saber o que eu presciso procurar , que direção seguir para resolver meu problema !!!

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...