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

240
Visualizações
jquery: unable to find elements from jQuery object

I am fetching HTML string and I want to construct a jQuery object from it and then perform operations but I am getting undefined.

    var data = '<h1>Hi World</h1';
    var html = '<div id="rendered">'+data+'</div>';
    //var content = $($.parseHTML(html));
    var content = $.parseHTML(html);

    console.log($(content).find('#rendered').html()) // it says undefined
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

find() is used to look for child elements. #rendered is the parent node in the HTML structure you create, so find() doesn't return anything. You need to use filter() instead as that includes the current node when searching.

Also note that $.parseHTML() isn't required - jQuery does this automatically when you provide a HTML-formatted string to the jQuery object contructor.

var data = '<h1>Hi World</h1';
var html = '<div id="rendered">' + data + '</div>';

console.log($(html).filter('#rendered').html())
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório
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