JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<a href="#" class="change">Old Text</a>
<br />
<a href="#" class="change">Another Old Text</a>
JavaScript
// http://stackoverflow.com/q/29054346/1055987
var
DELAY = 700,
clicks = 0,
timer = null,
restoreText = function(target, oldText, newText) {
target.html(newText); // set new text
setTimeout(function() {
target.html(oldText); // restore old text after n seconds
}, 2000);
}
$(".change").on("click", function(e) {
clicks++; //count clicks
var that = $(this); // $(".change")
if (clicks === 1) {
timer = setTimeout(function() {
// set new text and restore old one after n seconds
// parameters : target, oldText, newText
restoreText(that, that.html(), "new text")
clicks = 0; //after action performed, reset counter
}, DELAY);
return false
}
// double click otherwise
clearTimeout(timer); //prevent single-click action
// set new text and restore old one after n seconds
// parameters : target, oldText, newText
restoreText(that, that.html(), "new text")
clicks = 0; //after action performed, reset counter
}).on("dblclick", function(e) {
e.preventDefault(); //cancel system double-click event
});