Created
October 6, 2022 17:57
-
-
Save oxyc/e9b0491d7420e29dd7fc1d1562ca45e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="compare" data-compare-product> | |
<input type="text" class="compare__product-search" /> | |
<div class="compare__suggestions"></div> | |
<div class="compare__details"></div> | |
</div> | |
///// | |
for (const el of document.querySelectorAll('[data-compare-product]')) { | |
compareProduct.init(el); | |
} | |
//// | |
export default { | |
init(el) { | |
el.querySelector('.compare__product-search').addEventListener('keyup', async (e) => { | |
const suggestionContainer = el.querySelector('.compare__suggestions'); | |
suggestionContainer.innerHTML += '<span class="selection">Product 1</span>'; | |
}); | |
el.querySelector('.selection').addEventListener('click', async (e) => { | |
const detailsContainer = el.querySelector('.compare__details'); | |
detailsContainer.innerHTML = 'Updated text'; | |
}); | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment