My question is formed by two parts:
Thank you so much. Any kind of help would be kindly appreciated.
This is what I have so far:
HTML:
$('.answer_buttons a').on('click', function(e){
e.preventDefault();
$('.selected').removeClass('selected').hide().next().show().addClass('selected');
$.ajax({
type: "POST",
url: '',
data: {},
success: function(msj){
//alert('test');
//console.log(msj);
}
});
});
<form action="" method="post">
<input name="intr1" value="" type="hidden">
<p class="question selected" id="intreb_1">
Intrebarea 1?</p>
<input name="intr2" value="" type="hidden">
<p class="question " id="intreb_2">
Intrebarea 2?</p>
<input name="intr3" value="" type="hidden">
<p class="question " id="intreb_3">
Intrebarea 3?</p>
<input name="intr4" value="" type="hidden">
<p class="question " id="intreb_4">
Intrebarea 4?</p>
<input name="intr5" value="" type="hidden">
<p class="question " id="intreb_5">
Intrebarea 5?</p>
<div class="answer_buttons">
<a class="nu" href=""></a>
<a class="da" href=""></a>
</div>
</form>
It seems you want to select the next sibling .question
of the current .question.selected
element. For doing this you can use the .nextAll()
and .first()
methods:
$('.selected').removeClass('selected')
.hide()
.nextAll('.question')
.first()
.show()
.addClass('selected');
And for updating value of the previous input
sibling by using the className
of the clicked element you can use the .prev()
and .val()
methods.
$('.selected')...
.addClass('selected')
.prev('input')
.val($(this).hasClass('nu') ? 'no' : 'yes');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With