I have number as below
<div class="btn">
<span class="num-items">1</span>
</div>
<div class="btn">
<span class="num-items">2</span>
</div>
<div class="btn">
<span class="num-items">3</span>
</div>
<div class="btn">
<span class="num-items">4</span>
</div>
<div class="btn">
<span class="num-items">5</span>
</div>
$('.btn').click(function(){
var currentEl = [];
$(this).toggleClass('bg_red');
currentEl.push($(this));
if(currentEl.length >=3){
alert("You can pick only 3 item");
}
})
I want to add this element to an array every time I clicked on number so that when array length greater or equal to 3, I can alert message.
question from:https://stackoverflow.com/questions/65931017/how-to-add-current-clicked-element-to-an-array-in-jquery