1

I have the following statically programmed button:

<a class="btn dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)" id="action" disabled="disabled">

And want to check if the button is disabled so I can set the preventDefault() because, if it is not set to disabled (by another function) the button must do its work.

<script type="text/javascript">
$(document).ready(function(){    

 // IF ACTION BUTTON IS DISABLED, DISABLE DROPDOWN CLICK
 if ($('#action').is(':disabled')) {
 alert("inside if");
  event.preventDefault();
  return false; 
 };
});
</script>

But it never throws me the alert. I can see with inspect element the button has disabled="disabled" attribute so it should work. What am I doing wrong?

note: I am using jQuery, so if that is applicable then please point out :)

tvb
  • 783
  • 1
  • 10
  • 21

1 Answers1

1
 if ($('#action').prop('disabled', true)) {
     alert("inside if");
     event.preventDefault();
     return false; 
 };
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62