Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!