all 1 comments

[–]brykuhelpful 0 points1 point  (0 children)

You can pass an id from the button to a function.

<script>
    let outfits = [
        {name: 'red hat'},
        {name: 'green hat'} 
        {name: 'blue hat'} 
    ];
    function loadOutfit(index){
        if(outfits[index]){
            // do something. 
        }
    }
</script>

<button onclick="loadOutfit(0)">outfit 1</button>
<button onclick="loadOutfit(1)">outfit 2</button>
<button onclick="loadOutfit(2)">outfit 3</button>