I want to check if a button is enabled or disabled, but the button is added after pageload. How can I do this?
My code needs to show a message when the button is disabled and remove the message when the code is enabled.
My code:
jQuery(document).ready(function() {
"use strict";
if(jQuery('#checkoutbtn').prop(':disabled')){
console.log('disabled');
jQuery("#voorwaarden").css("display", "inline-block");
}else{
console.log('enabled');
jQuery("#voorwaarden").css("display", "none");
}
});
My html code:
<div class="checkoutvoorwaarden" id="voorwaarden">Ga akkoord met onderstaande voorwaarden om door te gaan:</div>
<button type="submit" title="<?php echo $this->__('Place Order') ?>" disabled="disabled" class="button btn-checkout" id="checkoutbtn" onclick="review.save();"><span><?php echo $this->__('Place Order') ?></span></button>
<p><input type="checkbox" class="checkbox chk" id="voorwaarden" style="display:inline;" required/><b> Ik ga akkoord met de algemene voorwaarden <em style="color:#ff2727;">*</em></b></p>
<p><input type="checkbox" class="checkbox chk" id="geboorte" style="display:inline;"/><b> Ik ben ouder dan 18 jaar <em style="color:#ff2727;">*</em></b></p>
Part of my jquery that only works when written like this (wrapped inside a document):
jQuery(document).on('change','.chk', function() {
var checkCount=jQuery('.chk:checked').length;
var totalCheckbox =jQuery('.chk').length;
totalCheckbox==checkCount ? jQuery("#checkoutbtn").prop('disabled', false):jQuery("#checkoutbtn").prop('disabled', true);
});
But I don't know how to use this .on('change') for the .is(:disabled) property.
onchangeevent?.Why include theis(':disabled').It only focuses the single element, not multiple