Jquery Add a delay in P text swap -
$(document).ready(function() { $("p").on("click", function() { var el = $(this); if (el.text() == el.data("text-swap")) { el.text(el.data("text-original")); } else { el.data("text-original", el.text()); el.text(el.data("text-swap")); } }); });
is possible add delay in jquery code?
use settimeout
sets timer executes function or specified piece of code once after timer expires.
$(document).ready(function() { $("p").on("click", function() { var el = $(this); settimeout(function() { if (el.text() == el.data("text-swap")) { el.text(el.data("text-original")); } else { el.data("text-original", el.text()); el.text(el.data("text-swap")); } }, 1000); }); });
Comments
Post a Comment