I have an array with the alphabet, each letter has a URL attached with it. I also have a list of buttons, each corresponding to a letter of the alphabet.
I want to retrieve the value from the array (url) based on which button the user clicks, the user may click multiple buttons.
So if the user click the button "C", I want to get to retrieve the URL associated with the letter "C" from the array.
I was able to loop through the #letters element's children and get the id of each button. I thought about comparing it against the array somehow but I got lost along the way.
I really have no solution in sight.
HTML
<div class="col-md-12" id="letters">
<a href="#" class="btn btn-primary" id="A">A</a>
<a href="#" class="btn btn-primary" id="B">B</a>
<a href="#" class="btn btn-primary" id="C">C</a>
</div>
Javascript
$(function() {
let array = {
'A' : 'http://example.com/A.png',
'B' : 'http://example.com/B.png',
'C' : 'http://example.com/C.png',
};
$.each(array, function(key, value) {
console.log('Initializing...', key + ' => ' + value);
});
let letters = $('#letters');
$.each(letters.children(), function(i) {
console.log(letters.children()[i].id); // get value of id tag
});
});