I’m wanting to add the Google Maps API div, <div id="map"></div>
within a card that’s dynamically added to the DOM, after a user has input a search. I’m able to append it the main div, as a test, but not within the card one I’m appending after the the card is inserted into the DOM.
Code is below.
Any help would be great. Thank you
const APIURL = 'https://restcountries.eu/rest/v2/name/'
const GOOGLE_MAPS_API = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyDhlU1KMTlTh4C__bTJBxbVA-s7wvQbO9E&callback=initMap'
const main = document.getElementById('main')
const form = document.getElementById('form')
const search = document.getElementById('search')
async function getCountryData(name) {
try {
const { data } = await axios.get(APIURL + name)
data.forEach(res => {
const countryData = res
addGMapsEl()
createCountryCard(countryData)
getLatLngPos(countryData)
} )
} catch (err) {
if(err.response.status == 404) {
createErrorCard('No countries found')
setTimeout(() => {
main.innerHTML = ''}
, 1500);
}
}
}
// Google Map API
function addGMapsEl() {
const script = document.createElement('script');
script.src = GOOGLE_MAPS_API;
script.defer = true;
document.head.appendChild(script);
const mapDiv = document.createElement('div')
mapDiv.id = 'map'
main.appendChild(mapDiv)
}
let map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 51, lng: 9},
zoom: 7
});
}
function createCountryCard(country) {
const cardHTML = `
<div class="content-container">
<div class="card">
<div class="wrapper">
<div class="card-title">
<h2>${country.name}</h2>
<h4>Capital: ${country.capital}</h4>
<h5>Population: ${country.population.toLocaleString('en')}</h5>
</div>
<div class="card-image">
<img
src="${country.flag}"
alt="${country.name +'-flag'}"
/>
</div>
</div>
<div class="wrapper">
<div class="map-content">
</div>
<div class="card-content">
<ul class="card-list">
<li><strong>Region:</strong> ${country.region}</li>
<li><strong>Subregion:</strong> ${country.subregion}</li>
<li><strong>Currency:</strong> ${country.currencies[0].name}<span> ${country.currencies[0].symbol}</span></li>
<li><strong>Spoken Language:</strong> ${country.languages[0].name}</li>
<li><strong>Timezone:</strong> ${country.timezones}</li>
</ul>
</div>
</div>
</div>
</div>
`
main.innerHTML += cardHTML
}
// Creates error card after no results found
function createErrorCard(msg) {
const cardHTML = `
<div class="card">
<h1>${msg}</h1>
</div>
`
main.innerHTML = cardHTML
}
// Clears the DOM on search
function clearDOM() {
main.innerHTML = ''
}
// Search Input
form.addEventListener('submit', (e) => {
e.preventDefault()
clearDOM()
const countryName = search.value
if(countryName) {
getCountryData(countryName)
search.value = ''
}
})
<body>
<div class="search-container">
<form id="form" class="form">
<input type="text" id="search" placeholder="Search for country..." />
</form>
</div>
<main id="main"></main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="script.js"></script>
</body>
clomiphene tablets – buy clomid online buy clomiphene
where can you buy viagra – viagra nyc 200 mg generic viagra
ivermectin 3 mg tabs – generic ivermectin cream ivermectin 8000 mcg
over the counter ed pills cvs – new treatments for ed erectile dysfunction medications
prednisone drug – prednisone 0.5 mg prednisone pill cost
where to buy sildenafil citrate – where can i buy viagra pills online buy sildenafil with visa
cialis 25mg – Cialis online us tadalafil 20mg coupon
ivermectin pills for humans – topical stromectol cost buy ivermectin 12mg
over the counter ed pills walmart – online medications rhino ed pills
ventolin price in india – generic ventolin price albuterol nebulizer
cytotec 200mg tablet – buy cytotec in singapore cytotec buy
doxycycline 20 mg coupon – doxycycline 100 mg capsule doxycycline pharmacy price
cost of neurontin 600 mg – neurontin 100 mg cost synthroid nz
tadalafil generic mexico – purchase tadalafil online
vardenafil hcl 20mg – cialis vardenafil online buy real vardenafil online
stromectol 3 mg tablet – ivermectin 0.5 lotion buy stromectol uk
accutane tablets uk – generic accutane price canadian pharmacy accutane with no prescription
buy amoxicilin 500 mg online – amoxil 250 buy amoxicilina noscript canada
methylprednisolone 4 mg tab – lyrica 75 mg capsule lyrica 75 mg medicine
custom written papers – write my essay paper research paper editing
uk viagra buy – Buy viagra no prescription required cheap viagra from india
no rx pharmacy – Cialis now where to buy cheap cialis
prednisone acetate – buy prednisone from india prednisone buying
buy ventolin inhaler – ventolin for sale ventolin cost uk
cytotec pharmacy uk – cytotec pills price in south africa cytotec 200mg online
doxycycline usa – prednisolone 25mg online prednisolone drug
stromectol 3 mg tablets price – ivermectpill.com ivermectin 0.5%
ivermectina 6mg – ivermectin 3 mg tablet dosage stromectol 12mg
sildenafil pills – canadian pharmacy sildenafil online pharmacy sildenafil
tadalafil cheap tadalafil – tadalafil citrate tadalafil generic online
accutane purchase canada – 100 mg accutane buy accutane 20mg online
buy assignments – pay essay writing buy a term paper online
buy oral stromectol – ivermectin buy australia topical ivermectin cost
where to buy vardenafil online – online pharmacy impotence definition
medicine hydroxychloroquine – plaquenil tablets 200mg prednisone 50 mg canada
cenforce 200 – kamagra 100 mg online cenforce 200
xenical bmi – orlistat dosage instructions orlistat medication reviews
cost of ivermectin 1% cream – stromectol uk coronavirus ivermectin for humans for sale
sildenafil 100 paypal – real viagra sites generic viagra cheap
no prescription needed pharmacy – cialis 5mg cheap cialis over the counter in canada
covid and ivermectin – purchase oral ivermectin ivermectin tablets for sale walmart
stromectol pharmacy – stromectol order online where to buy stromectol online
casino online games for real money – gambling games slots online
how to get prednisone over the counter – prednisone 60 mg tablets buy deltasone
prednisone 5mg online – prednisone corticosteroids prednisone generic
how to get accutane in india – buy accutane without prescription accutane 1mg
is world pharmacy store legit online pharmacy store in delhi
online pharmacy testosterone cypionate walgreens pharmacy technician application online
how much tadalafil to take 20 mg tadalafil
canadian pharmacy ed medications canadian pharmacy discount code
home sweet home essay research paper compare contrast essay example papers
buy plaquenil 200mg generic – buy plaquenil 400mg pill valacyclovir 1000mg ca
sildalis online buy – oral metformin cheap metformin 1000mg
buy generic ampicillin – buy hydroxychloroquine without prescription plaquenil 200mg ca
cost plaquenil 200mg – brand plaquenil 400mg plaquenil 400mg generic
viagra 150mg usa – cost tadalafil order tadalafil 40mg for sale
viagra 200mg prix – tadalafil sans ordonnance tadalafil 10mg pour homme
order prednisone – order prednisone 10mg generic prednisone 20mg brand
buy isotretinoin 10mg pill – buy amoxil 1000mg sale cheap amoxicillin generic
order lyrica 150mg online – generic cetirizine 5mg order zithromax 500mg generic
tizanidine 2mg usa – zanaflex generic gloperba cost
where to buy tadalafil on line tadalafil cost walmart
https://cialisusdc.com/ tadalafil without a doctor prescription
tadalafil order online no prescription tadalafil generic where to buy
tadalafil 20 mg cialis generic
viagra order viagra pills
cialis soft tabs tadalafil tablets
tadalafil cost walmart cheap generic cialis for sale
where to buy cialis without prescription what is tadalafil
tadalafil brands best price usa tadalafil
generic diazepam – cost of diazepam diazepam order online
i need a loan with bad crediti need a loan fast, need a loan of 5000 with bad credit. i need a loan desperately today need loan now need a loan been refused everywhere i need loan fast, cash advance loans what do i need, cash advance, cash advance loans, cash advance loans for 1500. Money management study of those commerce, financial institution .
non prescription cialis cialis walgreens evolution peptides tadalafil
price of viagra 100mg viagra from mexico to us viagra prescription medicine
australia online pharmacy viagra where to buy viagra online usa buy viagra 100mg
tadalafil soft tablets cialis black is it safe is there a generic equivalent for cialis
hrt online pharmacy pharmacy technician schools online Top Avana
order prescriptions online without doctor online pharmacy technician program cvs pharmacy little canada mn