Skip to content

Instantly share code, notes, and snippets.

@toadkicker
Last active August 29, 2015 13:59
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 toadkicker/10942948 to your computer and use it in GitHub Desktop.
Save toadkicker/10942948 to your computer and use it in GitHub Desktop.
boilerplate enable/disable button functions
function enableButton(el) { //el = '[attr="value"]'
//make it optional to send an el
var ele = document.querySelectorAll(el) || document.querySelectorAll('[type="submit"]');
if(ele.length === 0) { console.log('enableButton called but no button was found in the dom'); return; }
ele.innerHeight = ele.attr.getValue("data-btn-enabled-text");
ele.classList.remove("disabled");
ele.removeAttr('disabled');
}
function disableButton(el) {
//make it optional to send an el
var ele = el || document.querySelectorAll('[type="submit"]');
if(ele.length === 0) { console.log('enableButton called but no button was found in the dom'); return; }
ele.classList.add("disabled");
ele.attr("data-btn-enabled-text", ele.innerHTML);
ele.innerHTML = "One moment...";
ele.attr('disabled', 'disabled');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment