JSFiddle - React, Tailwind, and code Playground
JavaScript
var files = {
'group_1': [
'file1.pdf',
'file2.pdf',
'file5.pdf',
],
'group_2': [
'file3.pdf',
'file4.pdf',
'file5.pdf',
],
'group_3': [
'file1.pdf',
'file2.pdf',
'file3.pdf',
'file4.pdf',
'file5.pdf',
],
};
var btns = [
{
id: 'btn1',
label: 'Files1',
custom: 'group_1'
},
{
id: 'btn2',
label: 'Files2',
custom: 'group_2'
},
{
id: 'btn3',
label: 'Files3',
custom: 'group_3'
},
];
function createButton(btn, listener) {
const el = document.createElement('button');
el.setAttribute('id', btn.id)
el.setAttribute('data-custom', btn.custom);
el.textContent = btn.label;
el.addEventListener('click', listener);
document.body.appendChild(el);
return el;
}
function btnCallback(event) {
var custom = event.currentTarget.dataset.custom;
console.log('files:', files[custom]);
}
btns.forEach(function(btn) {
var buttonCreated = createButton(btn, btnCallback);
});