Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
select element after insert jquery javascript

I have a little problem which is the following:

I have a button which allows to generate html code, example:

               $( "#addBlockArray" ).click(function() {
     
       let idunique =  Math.floor(Math.random() * 100000);
     
           let array = 
           '\
           <divSpecialSelected class="selectedbloccss"  id= ' + idunique + '> edit\
           <table class="table table-hover" contenteditable="true"> \
       <thead>\
         <tr>\
           <th scope="col">#</th>\
           <th scope="col">First</th>\
           <th scope="col">Last</th>\
           <th scope="col">Handle</th>\
         </tr>\
       </thead>\
       <tbody>\
         <tr>\
           <th scope="row">1</th>\
           <td>Mark</td>\
           <td>Otto</td>\
           <td>@mdo</td>\
         </tr>\
         <tr>\
           <th scope="row">2</th>\
           <td>Jacob</td>\
           <td>Thornton</td>\
           <td>@fat</td>\
         </tr>\
         <tr>\
           <th scope="row">3</th>\
           <td colspan="2">Larry the Bird</td>\
           <td>@twitter</td>\
         </tr>\
       </tbody>\
     </table>\
     </divSpecialSelected>\
           '
     
           $( "#blocArray" ).append( array);
     
     
     });

However, when this code is generated, I am unable to use selectors to do actions on it

$("divSpecialSelected").on('click', function () { // that dont work, he dont find this selector
console.log("aaa");
document.getElementById(this.id).addEventListener('mousedown', mouseDown, false);
localStorage.setItem('id', this.id);
window.addEventListener('mouseup', mouseUp, false);

});

I think because it is not in the DOM loaded at the start. But how could I get around this problem?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda