Skip to content

Instantly share code, notes, and snippets.

@jabranr
Last active September 5, 2016 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabranr/705410c48326321d4da043aa62fd51a5 to your computer and use it in GitHub Desktop.
Save jabranr/705410c48326321d4da043aa62fd51a5 to your computer and use it in GitHub Desktop.
[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