'use strict'; (() => { // === DOM & VARS ======= const module = document.querySelector('.m-tours') || console.warn('element not found'); const DOM = { module, images: Array.from(module.querySelectorAll('img[data-description]')), infoBox: document.getElementById('info'), }; // const DefaultText = DOM.infoBox.querySelector('p').innerText; const defaultText = DOM.infoBox.innerHTML; // === INIT ============= const init = () => { DOM.images.forEach((img) => { img.addEventListener('mouseenter', showImgData); }); DOM.module.addEventListener('mouseleave', resetInfo); }; // === EVENTHANDLER ===== const showImgData = (e) => { const html = getInfoData(e.target); updateInfo(html); }; const resetInfo = () => updateInfo(defaultText); // === XHR/FETCH ======== // === FUNCTIONS ======== const getInfoData = (img) => { const { countryCode, flagName, description } = img.dataset; // let html = `

${img.alt}

`; let html = `

${flagName} ${img.alt}

`; html += `

${description}

`; return html; }; const updateInfo = (html) => { DOM.infoBox.innerText = ''; DOM.infoBox.insertAdjacentHTML('afterbegin', html); }; init(); })(); //
//

// Italian Flag // Colosseum //

//

// The Colosseum or Coliseum, also known as the Flavian Amphitheatre or Colosseo, is an oval amphitheatre in... //

//