JSFiddle - React, Tailwind, and code Playground
by David Kyle
HTML
<div id="actions">
<form>
<input type="submit" id="first-button" value="Submit" />
<br />
<input type="button" id="second-button" value="Delete" />
<br />
<input type="button" id="third-button" value="Cancel" />
</form>
</div>
JavaScript
$(function () {
//Setup the click for all of the buttons (these could be hyperlinks or any other element as well).
$("#actions").find("input[type='submit'], input[type='button']").click(function (e) {
//Do some conditional stuff based on the element that triggered the event
var sender = $(e.currentTarget);
switch (sender.val()) {
case "Delete":
var shouldDelete = confirm("Are you sure you want to delete?");
break;
case "Submit":
alert("Submit clicked.");
break;
case "Cancel":
alert("Cancelled.");
break;
default:
alert("Unknown clicked.");
break;
} // end switch
e.preventDefault();
});
});