code of search filter button using html ,css and java script
image;---
code:---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search Filter</title>
<style>
body {
font-family: Arial;
padding: 20px;
}
#search {
padding: 10px;
width: 300px;
margin-bottom: 20px;
}
.result {
padding: 8px;
border-bottom: 1px solid #ccc;
}
</style>
</head>
<body>
<h2>Search Countries</h2>
<input type="text" id="search" placeholder="Type to search...">
<div id="results"></div>
<!-- <script src="script.js"></script> -->
<script>
const countries = [
"India", "Indonesia", "United States", "United Kingdom",
"Nepal", "Nigeria", "Germany", "Greece", "China", "Canada",
"Japan", "South Africa", "Sri Lanka", "Russia", "France"
];
const searchInput = document.getElementById("search");
const resultsDiv = document.getElementById("results");
searchInput.addEventListener("input", function () {
const keyword = searchInput.value.toLowerCase();
const filtered = countries.filter(country =>
country.toLowerCase().includes(keyword)
);
// Display the filtered results
resultsDiv.innerHTML = "";
if (filtered.length === 0) {
resultsDiv.innerHTML = "<p>No match found</p>";
} else {
filtered.forEach(country => {
const div = document.createElement("div");
div.classList.add("result");
div.textContent = country;
resultsDiv.appendChild(div);
});
}
});
</script>
</body>
</html>
thank you
Comments
Post a Comment