I have three rows of button, I want to add text of button to array (firstRowArr, secondRowArr, thirdRowArr). If firstRowArr bigger then secondRowArr and thirdRowArr, secondRow and thirdRow's button can be selected only one. If secondRowArr if bigger than firstRowArr and secondRowArr, firstRowArr and thirdRowArr can be selected only one. And the third case is the same as case one and case two.
##index.html
<div class="row">
<div class="col d-flex justify-content-between" id="firstRow">
<button class="ball">0</button>
<button class="ball">1</button>
<button class="ball">2</button>
<button class="ball">3</button>
</div>
</div>
<div class="row">
<div class="col d-flex justify-content-between" id="secondRow">
<button class="ball-second">0</button>
<button class="ball-second">1</button>
<button class="ball-second">2</button>
<button class="ball-second">3</button>
</div>
</div>
<div class="row">
<div class="col d-flex justify-content-between" id="thirdRow">
<button class="ball-third">0</button>
<button class="ball-third">1</button>
<button class="ball-third">2</button>
<button class="ball-third">3</button>
</div>
</div>
##script.js
var firstRowArr = [];
var secondRowArr = [];
var thirdRowArr = [];
$('.ball').each(function () {
$(this).click(function () {
$(this).toggleClass('active-ball');
if($(this).hasClass('active-ball')) {
firstRowArr.push($(this).text());
if(firstRowArr.length >=2){
// button in secondRow and thirdRow can be selected only one button
}
}
});
});
$('.ball-second').each(function () {
$(this).click(function () {
$(this).toggleClass('active-ball');
if($(this).hasClass('active-ball')) {
secondRowArr.push($(this).text());
if(secondRowArr.length >=2){
// button in firstRow and thirdRow can be selected only one button
}
}
});
});
$('.ball-third').each(function () {
$(this).click(function () {
$(this).toggleClass('active-ball');
if($(this).hasClass('active-ball')) {
thirdRowArr.push($(this).text());
if(thirdRowArr.length >=2){
// button in firstRow and secondRow can be selected only one button
}
}
});
});