Reputation: 21
I have to disable a button when the page is loading.
How do I enable the button after fully loading the page, using jQuery or JavaScript?
Upvotes: 2
Views: 9758
Reputation: 2211
This is based on @Bang Dao's answer but using native JavaScript.
Disable the button from the beginning:
<button id="button" disabled>A button</button>
And then listen for the DOMContentLoaded
event on document
:
document.addEventListener('DOMContentLoaded', function() {
const button = document.getElementById('button');
button.disabled = false;
});
Upvotes: 0
Reputation: 137
add a disabled property for the button and in the script, document ready function remove disabled function.
$("#buttonID").prop('disabled',false)
Upvotes: 0
Reputation: 495
Or you can do
<body onload="load()">
and
<script type="text/javascript">
function load()
{
document.getElementById("buttonID").disabled=true;
}
</script>
Upvotes: 0
Reputation: 5102
Disable any button from the beginning:
<input type="button" disabled="disabled" />
And add the enable to window ready function
$(document).ready(
function(){
$("input[type=button]", "<input[type=submit]", "input[type=reset]").each( //add more selector here if you want
function(){
if($(this).attr("disabled"))
$(this).attr("disabled", false); //enable button again
}
);
}
);
Upvotes: 2