Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[jQuery] Toggle multiple buttons at same with different text
$.fn.extend({
disableCta: function() {
this.prop('disabled', true);
// or use your own class
this.addClass('btn--disabled');
// retain current text of the CTA in custom data attribute
// Used html() assuming it is a <button> element
this.attr('data-value', this.html());
// or use whatever text to show while waiting
this.html('Submitting...');
return this;
},
enableCta: function() {
this.prop('disabled', false);
// or use your own class
this.removeClass('btn--disabled');
// restore original text for the CTA
// Used html() assuming it is a <button> element
this.html(this.attr('data-value'));
// Remove custom data attribute from CTA
this.removeAttr('data-value');
return this;
}
});
// Use
$('#submit-btn').disableCta();
$('#submit-btn').enableCta();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.