I'm trying to wrap all city texts under the Location column, with a link to their specific location page on a website. So Cambridge would be wrapped in a link tag going to the Cambridge page, Timmins would be wrapped in a link tag going to the Timmins page, etc.
I've started off with just two links to try and get this working. Looping through the td's within the location column, and if the value equals specific text, add a link to it. Trying to get it to work.
JS
/////// Grab the Locations column ///////
let col5 = document.querySelectorAll("td:nth-child(5)");
// Cities Data
const cities = [
{
id: 1,
city: 'Cambridge',
link: '/locations/cambridge'
},
{
id: 2,
city: 'Timmins',
link: '/locations/timmins'
}
]
/////// Link up all td's to location pages ///////
// Loop over locations column
for (let i = 0; i < col5.length; i++) {
// If it matches the specific city, wrap text around link tag linking to specific location
if (col5.innerHTML === cities[0].city) {
// Set Links Info
a.setAttribute("href", cities[0].link);
// Append
col5[i].appendChild(a);
} else if (col5.innerHTML === cities[1].city) {
// Set Links Info
a.setAttribute("href", cities[1].link);
// Append
col5[i].appendChild(a);
}
}