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

178
Views
How to make always only 3 elements appear even after 1 of them is appended?

I need only max 3 elements to appear on the screen at all times and if one of them is removed, then the next in line takes its place and so on till the are no elements.

Here is the code snippet:

<div class="mob-keys-container" id="mob-keys-container">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_1_mob" src="./images/5.1.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_2_mob" src="./images/5.2.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_3_mob" src="./images/5.3.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_4_mob" src="./images/5.4.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_5_mob" src="./images/5.5.png" alt="key">
        <img class="answerIcon mobIcon active" draggable="true" id="answer_6_mob" src="./images/5.6.png" alt="key">

 </div>

And here is the best code that kinda works:

$('.info-mob').on('click', () => {
        $('#mob-keys-container').toggle();
        $('#mob-keys-container').children().slice(0, 3).show();
    });

.info-mob opens a tab that contains all the elements and while it's open there should be max 3 elements. Everything works fine if I close and open up again that tab but I need it to be more dynamic and always be max 3 elements even if I append one with different function.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think this will solve your issue with help of CSS

#mob-keys-container *{
  display:none;
}

#mob-keys-container *:nth-child(-n+3){
  display:block;
}
about 4 years ago · Juan Pablo Isaza 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!