Skip to content
Advertisement

How to limit amount of selected in custom select menu in javascript?

How to limit amount of selected in custom select menu in javascript?

I want to make a custom select menu where you can select items in it. This is my code for now:

JavaScript
JavaScript
JavaScript

What it does now is fine, I just want to add the limitation so that you can only select two items. This is because I want to make a game similar to memory.

Does anyone know how to do this?

Advertisement

Answer

Just count selected items, create variable let count = 0;, add count increase on selection add check on count before selecting.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement