Buck Buck - 1 year ago 80
jQuery Question

Disable a button dynamically created

I have a button created in ajax event (I call some data and I create a button at the end).

How do I disable it?

I try:

$(document).on("click", ".sendLead", function(event) {
$(".sendLead").disabled = true;
some code...

but it does not work !

Any idea ?

Answer Source

disabled is a boolean attribute that you have to set with the prop() method or the attr() method on your element. So simply try:

$('.sendLead').click(function(event) {
  $(".sendLead").prop('disabled', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="sendLead">Click</button>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download