JSFiddle - React, Tailwind, and code Playground
HTML
<button id="btn">Buy Now</button>
<h2 id="result"></h2>
CSS
button {
padding: 10px;
background: dodgerblue;
color: white;
border: none;
border-radius: 2px;
font-weight: bold;
}
JavaScript
var button = document.getElementById("btn");
var result= document.getElementById("result");
button.onclick = function() {
var buy = confirm("Are you sure you want to purchase now?");
if (buy == true) {
result.innerText = "Item has been purchased";
} else {
result.innerText = "You did not purchase the item";
}
}