JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Cards Library corresponding to selected Badge below -->
<div id="libraryList"></div>
<!-- Badges Menu beneath the card library-->
<div class="badgeLibrary">
<ul>
<li><button class="badge" data-day="1"></li>
<li><button class="badge" data-day="2"></li>
<li><button class="badge" data-day="3"></li>
</ul>
</div>
JavaScript
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
var cardlibrary = JSON.parse(xhr.responseText);
var statusHTML = '<ul class="libraryCard-container">';
for (var i=0; i<cardlibrary.cards.length; i ++) {
//If selected card data is equal to a data attribute
if (cardlibrary.cards[i].day === 1)) {
statusHTML += '<li><h3>';
statusHTML += cardlibrary.cards[i].title;
statusHTML += '</h3></li>';
}
} // end for loop
statusHTML += '</ul>';
document.getElementById('libraryList').innerHTML = statusHTML;
}
};
xhr.open('GET', 'js/json/cards.json');
xhr.send();
//From separate cards.json file
{
"cards": [{
"day": 1,
"title": "The Netherlands",
}, {
"day": 1,
"title": "Germany",
}, {
"day": 2,
"title": "France",
}
}