Last active
August 29, 2015 13:59
-
-
Save toadkicker/10942948 to your computer and use it in GitHub Desktop.
boilerplate enable/disable button functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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