Created
January 10, 2020 15:38
-
-
Save andregardi/a9af2e485cf775c9f33ad3841e1412ce to your computer and use it in GitHub Desktop.
This file contains 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
<h1>Products catalog</h1> | |
<h2>Apple <button value="apple">Add to cart</button></h2> | |
<h2>Banana <button value="banana">Add to cart</button></h2> | |
<h2>Orange <button value="orange">Add to cart</button></h2> | |
<script> | |
const addToCart = e => window.parent.postMessage(e.target.value, "*"); | |
document | |
.querySelectorAll("button") | |
.forEach(button => button.addEventListener("click", addToCart)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment