You'd use jQuery's val() to set the value, and with a callback it's easy to append to the value.
A small plugin that handles this could be useful, something like
$.fn.dots = function(time, dots) {
return this.each(function(i,el) {
clearInterval( $(el).data('dots') );
if ( time !== 0 ) {
var d = 0;
$(el).data('dots', setInterval(function() {
$(el).val(function(_,v) {
if (d < dots) {
d++;
return v + '.';
} else {
d = 0;
return v.substring(0, v.length - dots)
}
})
}, time));
}
});
}
Which you'd call like
$('.elements').dots(600, 3);
and can be cancelled by just passing zero
$('.elements').dots(0);
Here's a demonstration showing how easy it is to use.
$.fn.dots = function(time, dots) {
return this.each(function(i,el) {
clearInterval( $(el).data('dots') );
if ( time !== 0 ) {
var d = 0;
$(el).data('dots', setInterval(function() {
$(el).val(function(_,v) {
if (d < dots) {
d++;
return v + '.';
} else {
d = 0;
return v.substring(0, v.length - dots)
}
})
}, time));
}
});
}
$(document).ready(function() {
$('#dots').on('click', function() {
$(this).val('Proccessing').prop('disabled',true).dots(600, 3);
$('#cancel').show();
});
$('#cancel').on('click', function() {
$(this).dots(200, 10);
$('#dots').dots(0);
setTimeout(function() {
$('#dots').prop('disabled', false).val('Pay');
$('#cancel').hide().dots(0);
},2000);
}).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="dots" type="button" value="Pay" />
<br /><br />
<input id="cancel" type="button" value="Cancel dots" />