Я хочу сбросить цвет из моего eventListener, поэтому при нажатии следующего элемента цвет будет сброшен из предыдущего элемента.
import "bootstrap/dist/css/bootstrap.css";
const root = document.getElementById("root");
var tbody = document.getElementById("tbody");
var svg = document.getElementById("svg");
const country = "https://restcountries.eu/rest/v1/alpha?codes=";
var resetColor;
svg.addEventListener("load", function() {
var svgDoc = svg.contentDocument;
[...svgDoc.querySelectorAll("path")].forEach(path => {
path.addEventListener("click", e => {
getCountryNew(path.id);
path.style.fill = "#ff9900";
});
});
});
function getCountryNew(landcode) {
fetch(country + landcode)
.then(res => res.json())
.then(countries => {
var c = countries.map(country => {
return (
"<tr>" +
"<td>" +
country.name +
"</td>" +
"<td>" +
country.capital +
"</td>" +
"<td>" +
country.altSpellings +
"</td>" +
"<td>" +
country.region +
"</td>" +
"<td>" +
country.population +
"</td>" +
"<td>" +
country.languages +
"</td>"
);
});
tbody.innerHTML = c;
});
}
Я предполагаю, что должен сохранить Id путей и затем сбросить его перед циклом, но мои решения только полностью сломали мою выборку.