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

143
Visualizações
Jquery Show just one Item by the same class after click-event

i am new in scripting Jquery/Javascript and actually i've some struggle. How can i show one item by the same class without affect the other items?

My code:

$(function() {
  $('.embedContainer > .myPosterImage').on('click', function() {
    $('.embedContainer > .myPosterImage').hide();
    $('.embedContainer > embed').show();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="embedContainer">
  <img class="myPosterImage" src="img/websites/01_documentation.jpg" data-original="img/websites/full/01_full.jpg" />
  <embed src="img/websites/Concept.pdf" width="563.41" height="375.98"></embed>
</div>

<div class="embedContainer">
  <img class="myPosterImage" src="img/websites/01_documentation.jpg" data-original="img/websites/full/01_full.jpg" />
  <embed src="img/websites/Concept.pdf" width="563.41" height="375.98"></embed>

</div>

Thanks a lot.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The first line will hide all of them, which may be what you want to do (if you want to collapse all and expand the clicked one, for example):

$('.embedContainer > .myPosterImage').hide();

But as you've found, this second line will also show all of them:

$('.embedContainer > embed').show();

What you can do is traverse the DOM starting from the element which was clicked (this within the click event handler). In this case you'd traverse up the DOM (using closest() for example) to a common parent element and then back down (using find() for example) to the target element.

Something like this:

$(this).closest('.embedContainer').find('embed').show();
about 4 years ago · Santiago Trujillo 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