Basically I've had a request that (for a quiz) there is a group of checkboxes, the person selects as many as they want. Then on clicking the button feedback is displayed depending on what they selected.
Currently this is just one message if all checkboxes are selected and another if 0 to 4 are selected.
I had some JS that returned feedback based on the data-
attribute which I didn't know if I could reuse/rework. But wondering if it's best to just have 2 hidden messages and just display/slide open to the relevant one on click - that's the bit I need help with.
$(".quiz__item .btn").click(function () {
var current_feedback = $(this).attr("data-feedback");
var current_value = $(this).attr("data-value");
var contentHeight = $(".quiz__feedback").outerHeight(true);
$(this).parents(".quiz__item").find(".quiz__feedback p").html(current_feedback).removeClass("true false").addClass(current_value).slideDown(200);
});
.hide {
display: none;
}
.check-group,
.btn {
margin-bottom: 24px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="quiz">
<div class="quiz__item">
<h3>Checkboxes</h3>
<div class="check-group">
<label class="checkbox"><input type="checkbox">Option 1</label><br />
<label class="checkbox"><input type="checkbox">Option 2</label><br />
<label class="checkbox"><input type="checkbox">Option 3</label><br />
<label class="checkbox"><input type="checkbox">Option 4</label><br />
<label class="checkbox"><input type="checkbox">Option 5</label>
</div>
<a href="#" class="btn">Submit</a>
<div class="quiz__feedback">
<p class="false hide">Statement one lorem ipsum dolor sit amend</p>
<p class="true hide">Statement two lorem ipsum dolor sit amend</p>
</div>
</div>
</div>