• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 93
  • Last Modified:

Jquery each function onclick problem

Hello experts.
I need help with my js code.
I have div s with the same class mainlist , all are hidden except the first one.
I try to hide each  div and show the next one with the same class on button click.
I m trying to do this with each function to find the no hidden div but it is not working.
Any help?

$('form#Form1').on('click', 'button.nextstep', function() {
    $('div[class="mainlist"]').each(function(i, obj) {
        if (obj.css('display') !== 'none') {
            var tmp1 = obj;
        }
    });
    var tmp2 = tmp1.next('div.mainlist');
    tmp1.hide();
    tmp2.show();
});
0
Panos
Asked:
Panos
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
You can do it very simple.
Something like this:
$('form#Form1').on('click', 'button.nextstep', function() {
	
  var current = $('div.mainlist:visible') || $('div.mainlist').first();
  current.hide().next().show();
  return false;
});

Open in new window

Of course, you still need to validate is you're at the last one already or something like that, but as per your question, this works.

Heres a working sample
0
 
PanosAuthor Commented:
Hi Alexandre Simões
Thank you for your help. The code is doing the job.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now