ኮዱ እና የሚሠሩ ምሳሌ ገጾች የመጀመሪያ መለያዎቻቸውንና የምሳሌ ጽሑፋቸውን ይይዛሉ። ትምህርቱ እና የፋይል መመሪያዎች በእርስዎ ቋንቋ ያብራሯቸዋል።
// Filter the existing cards; do not rebuild their content or change their order.
const filters = document.querySelector(".filters");
const buttons = [...filters.querySelectorAll("button[data-filter]")];
const cards = [...document.querySelectorAll(".project-card")];
const status = document.querySelector("#project-status");
const noResults = document.querySelector("#no-results");
function showProjects(category) {
let visibleCount = 0;
for (const card of cards) {
const matches = category === "all" || card.dataset.category === category;
card.hidden = !matches;
if (matches) visibleCount += 1;
}
for (const button of buttons) {
button.setAttribute("aria-pressed", String(button.dataset.filter === category));
}
status.textContent = `${visibleCount} ${visibleCount === 1 ? "project" : "projects"} shown.`;
noResults.hidden = visibleCount !== 0;
}
for (const button of buttons) {
button.addEventListener("click", () => showProjects(button.dataset.filter));
}
// Without JavaScript, all cards remain readable and unused controls stay hidden.
filters.hidden = false;
showProjects("all");