Flags App
About this app
Click a button to display the flag of each country
Flags App Flags App Enter Country Code: Show Flag
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Flags App</title>
<meta name="description" content="Click a button to display the flag of each country">
<meta name="keywords" content="flags, countries, app">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
document.addEventListener("DOMContentLoaded", function() {
// Function to display the flag when the button is clicked
function displayFlag(country) {
// Get the container element
var container = document.getElementById("flag-container");
// Clear the container
container.innerHTML = "";
// Create the image element for the flag
var flagImg = document.createElement("img");
flagImg.src = "https://www.countryflags.io/" + country + "/shiny/64.png";
// Append the flag image to the container
container.appendChild(flagImg);
}
// Event listener for button click
$("#btn-show-flag").click(function() {
// Get the country code from the input field
var country = $("#input-country").val();
// Call the displayFlag function with the country code
displayFlag(country);
});
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
.container {
text-align: center;
margin-top: 50px;
}
h1 {
font-family: 'Roboto', sans-serif;
font-size: 24px;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 20px;
}
#flag-container {
margin-top: 20px;
}
#flag-container img {
width: 100px;
height: auto;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Flags App</h1>
<div class="form-group">
<label for="input-country">Enter Country Code:</label>
<input type="text" id="input-country" class="form-control" placeholder="e.g. us, fr, gb">
</div>
<button id="btn-show-flag" class="btn btn-primary">Show Flag</button>
<div id="flag-container"></div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!