JSFiddle - React, Tailwind, and code Playground
by klarstil
HTML
<button class="test-me">
Test me!
</button>
JavaScript
function random() {
return new Promise(function(fulfill, reject) {
if (Math.random() > 0.5) {
fulfill('yes');
} else {
reject(new Error('oh no something went wrong'));
}
});
}
$('.test-me').on('click.test-me', function() {
random().then(function(results) {
alert('Success');
}).catch(function(err) {
alert('Error: ' + err.message);
});
});