Jquery Delay Function Not Working
I have an password field and an small icon on right and I want to show the inputted password for 2 sec when user click on the icon. What I have done is. $('#showpass').click(functi
Solution 1:
Delay only works with functions that use the jQuery queue such as animations, thus you are getting no delay between setting the type to text and type back to password.
Your particular issue can be solved with setTimeout()
.
$("#showpass").click(function(){
var pass = $('#pass').attr('type','text');
setTimeout(function() {
pass.attr('type','password');
}, 2000);
);
Solution 2:
The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.
better use it only for animation issues :
use setTimeout instead.
Post a Comment for "Jquery Delay Function Not Working"