jQuery Show/Hide
HTML
<html>
<head>
<title>jQuery Show/Hide Test</title>
</head>
<body>
<div class="btn-group ">
<button id="actives" type="button">Actives</button>
<button id="inactives" type="button">Inactives</button>
<button id="all" type="button">All</button>
</div>
<div id="apiDiv"></div>
</body>
</html>
CSS
.card.card-found {
border: 2px solid green;
margin: 5px;
}
JavaScript
function create_apiDiv(api, inputId, inputName, inputClass) {
var value = [1,3]; // List of Divs with checkboxes initialized as "checked"
var newDiv = jQuery("<div>");
newDiv.addClass("card card-found");
var html = '';
html += ' <div class="card-header">\n';
if (api.hasOwnProperty("iconClass") && api.iconClass.length > 0) {
html += ' <i class="fa fa-fw ' + api.iconClass + '"></i>\n';
}
html += api.hasOwnProperty("name") ? api.name : api.id + '\n';
html += ' </div>\n';
html += ' <div class="card-body">\n';
html += ' <p>' + api.description + '</p>\n';
html += ' </div>\n';
html += ' <div class="card-button">\n';
html += ' <input class="' + inputClass + ' ace ace-switch ace-switch-3" name="' + inputName + '"';
html += ' id="' + inputId + '-' + api.id + '" type="checkbox" value="' + api.id + '" ';
html += value.includes(api.id) ? 'checked="checked"' : '';
html += ' tabindex="' + api.id + '">\n';
html += ' <span class="lbl">Label ' + api.id + '</span>\n';
html += ' </div>\n';
newDiv.append(html);
return newDiv;
}
function activesHandler() {
jQuery(".card-button > input:checked").parents(".card.card-found").show();
jQuery(".card-button > input:not(:checked)").parents(".card.card-found").hide();
}
function inactivesHandler() {
jQuery(".card-button > input:checked").parents(".card.card-found").hide();
jQuery(".card-button > input:not(:checked)").parents(".card.card-found").show();
}
function allHandler() {
jQuery(".card.card-found").show();
}
function buildDivs() {
var newDiv;
var test_data = [
{id: 1, name: "Object#1", description: "Object One Description"},
{id: 2, name: "Object#2", description: "Object Two Description"},
{id: 3, name: "Object#3", description: "Object Three Description"}
];
for (var api of test_data) {
newDiv = create_apiDiv(api, api.id, "inputName", "inputClass");
jQuery("#apiDiv").append(newDiv);
...