I have 15 list items. I allow user to pick only 5 out of them. Then I put this info into the array and submit to the server.
<li><a href="#" id="item1" class="select">Item One</a></li> ... etc.
Then I use this code to toggle class of selected items
function SelectPrizes (){
$('a.select').click(function() {
$(this).toggleClass("selected");
$(this).text($(this).text() == 'Choose prize' ? 'Selected' : 'Choose prize');
return false;
});
}
My question is, how to allow only 5 selections and add only selected items to an array by ID.
I understand that I can filter by hasClass('selected'), but I can't figure out the right syntax for that.