mirko
mirko

Reputation: 65

Jquery $(this).parent().next();

I will jump to the <fieldset> with a class "secound", but the jump doesn't work. What is wrong in my code? Sorry for my english and I hope you can help me?

$(".next").click(function(){
    textnext = "next1";
    current_fs = $(this).parent();
    next_fs = $(this).parent().next();

    if( textnext == $(".next").val()){
        next_fs = $(this).parent(".secound").next();
    }
    next_fs.show();
}
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

<fieldset style="height:100vh">
    <input type="button" name="next" class="next action-button" value="next1" />
</fieldset>
<fieldset style="height:100vh" class="first">
    <input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset style="height:100vh" class="secound">
    <input type="button" name="next" class="next action-button" value="Next" />
</fieldset>

Upvotes: 1

Views: 2240

Answers (4)

mirko
mirko

Reputation: 65

This is the code and i will not jump to the next fieldset. i will jump to a custom fieldset with a class. http://thecodeplayer.com/walkthrough/jquery-multi-step-form-with-progress-bar

Upvotes: 0

alexqoliveira
alexqoliveira

Reputation: 379

that's what you are trying to do?

$(".next").click(function(){
   
    var textnext = "next1";
  
    var current_fs = $(this).parent();
  
    var next_fs = $(this).parent().nextAll('.secound');
  
   $('body').scrollTop( next_fs.offset().top);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id='test'>
  
<fieldset style="height:50vh">
    <input type="button" name="next" class="next action-button" value="next1" />
</fieldset>
<fieldset style="height:50vh" class="first">
    <input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset style="height:50vh" class="secound"  >
    <input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
</div>

Upvotes: 0

Bak
Bak

Reputation: 262

If you want to compare the value of the button you clicked with

textnext

, you need to do

if( textnext == $(this).val()){
    next_fs = $(this).parent(".secound").next();
}

Upvotes: 1

KDot
KDot

Reputation: 506

The .secound fieldset isn't a parent of the element you are clicking on.

Upvotes: 0

Related Questions