Country Code Finder
🌍 Country Code Finder
Find the dialing code of any country easily!
body {
background: linear-gradient(120deg, #f6d365 0%, #fda085 100%);
color: #333;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.title {
color: #ffffff;
font-size: 2.5rem;
font-weight: bold;
}
.subtitle {
color: #f9f9f9;
font-size: 1.2rem;
}
.search-box {
max-width: 400px;
margin: auto;
border: 2px solid #ffffff;
border-radius: 20px;
padding: 10px;
font-size: 1rem;
}
.search-box:focus {
outline: none;
border-color: #4caf50;
box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}
.result-section {
font-size: 1.2rem;
color: #ffffff;
margin-top: 20px;
}
.show-all {
background-color: #4caf50;
border: none;
font-size: 1rem;
padding: 10px 20px;
color: #ffffff;
border-radius: 20px;
transition: background-color 0.3s;
}
.show-all:hover {
background-color: #45a049;
}
.list-group {
max-width: 400px;
margin: auto;
text-align: left;
}
.list-group-item {
background: #ffffff;
border: 1px solid #4caf50;
color: #333;
padding: 10px 15px;
margin-bottom: 5px;
transition: transform 0.3s;
}
.list-group-item:hover {
transform: scale(1.05);
cursor: pointer;
}
const countries = [
{ name: "United States", code: "+1" },
{ name: "India", code: "+91" },
{ name: "United Kingdom", code: "+44" },
{ name: "Australia", code: "+61" },
{ name: "Canada", code: "+1" },
{ name: "Germany", code: "+49" },
{ name: "France", code: "+33" },
{ name: "Japan", code: "+81" },
{ name: "China", code: "+86" },
{ name: "Brazil", code: "+55" },
];
const input = document.getElementById("countryInput");
const result = document.getElementById("result");
const countryList = document.getElementById("countryList");
const showAllBtn = document.querySelector(".show-all");
// Search by country name
input.addEventListener("input", () => {
const searchTerm = input.value.toLowerCase().trim();
const country = countries.find((c) =>
c.name.toLowerCase().includes(searchTerm)
);
if (country) {
result.innerHTML = `
${country.name}: ${country.code}
`;
} else {
result.innerHTML = searchTerm
? `
Country not found!
`
: "";
}
});
// Show all countries
showAllBtn.addEventListener("click", () => {
countryList.innerHTML = "";
countries.forEach((country) => {
const li = document.createElement("li");
li.className = "list-group-item";
li.textContent = `${country.name} - ${country.code}`;
countryList.appendChild(li);
});
countryList.classList.toggle("d-none");
});