I am currently working on a project that involves 4 div
elements, each with its own value (for example: 0
). There is also a button with plus and minus functionality to change the values in each box. Additionally, there is a "set next" button to move on to the next box and repeat the process.
The challenge I am facing is how to efficiently select the next div
, update its value using the same plus and minus buttons, and then move on to the subsequent div
until reaching the end. The process should then loop back to the first div
. Below is an excerpt of my code:
<div class="code_div">
<div class="code_area">
<p id="number1">00</p>
</div>
<div class="code_area2">
<p id="number2">00</p>
</div>
<div class="code_area3">
<p id="number3">00</p>
</div>
<div class="code_area4">
<p id="number4">00</p>
</div>
var value = 0;
var plus = false;
var minus = false;
$(document).ready(function() {
$('#set_next').click(function() {
});
$('#minus').click(function() {
minus = false;
plus = true;
if (plus == true) {
value -= 5;
}
displayValue()
});
$('#plus').click(function() {
minus = true;
plus = false;
if (minus == true) {
value += 5;
}
displayValue()
});
});
function displayValue() {
document.getElementById("number1").innerHTML = value;
}
If anyone has any insights or suggestions on how to tackle this issue, I would greatly appreciate it!