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

110
Views
Next element with jQuery

I need to move on to the next element. My code shows 3 different cards and put the option in ddbb, but when click on the option I need to pass the 'screen-view' to the next card when sucess is ok. I tried .next('.card').toggle() and .show() but don't work, any advice?

My template:

{% for standard in standards %}
<div class="card mx-auto mt-4 card-standard" style="width: 95%;" data-aos="fade-up">
    ...
</div>

{% endfor %}


<script type="text/javascript">
    AOS.init({
        duration: 1200,
    })

    $(document).on('click', '.alternative', function () {
        const $this = $(this)
        const alternative_pk = $this.data('alternative-pk');
        console.log(alternative_pk)

        const url = $('.tabla-standard').data('alternative-url');
        $.ajax({
            ...
            success: function (json) {
                if (json.success) {
                    console.log("ok")
                }
            }
        });

        $('.card-standard').next().show();
    })
</script>

If anyone knows how to solve this please comment

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

0

I see a few things here that are going to cause you problems with what you're trying to do.

First, your call to $('.card-standard').next().show(); is not happening when success is okay, but instead it happens immediately after the AJAX call begins. With JavaScript, functions are run to completion, before any nested callbacks occur. If you want to switch cards on success (when your success callback executes), you need to switch at the same time you say console.log("ok").

Second, you're going to get some strange results from $('.card-standard').next().show();, because you seem to expect it to find a single element, but that is going to find all elements with class .card-standard. Then for each one, it will go to the next and show it. That means it will show every card except the first, which it leaves untouched.

Third, at no point do you hide the current card. I don't know what your UI looks like, but if only one card should be on screen at a time, shouldn't you hide it in here, too?

Maybe you should put in your success handler something like this:

$this.parent("card").hide();
$this.parent("card').next().show();
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!