title: disable button using jquery and enable after action is completed using jquery
body: <p>I would like to write a if else statement in a jQuery. If the button is click, disable the button until the action is completed then only enable back. This is the codes I currently have. When I navigate to the page, the action kept looping non stop. Pls bear with me as I'm still new to jQuery.</p>
  
  <p>FYI, I am using primefaces commandbutton</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3c.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:hx="http://www.ibm.com/jsf/html_extended"&gt;
  &lt;h:head&gt;
      &lt;title&gt;ma1009.xhtml&lt;/title&gt;
      &lt;meta http-equiv="keywords" content="enter,your,keywords,here" /&gt;
      &lt;meta http-equiv="description"
      content="A short description of this page." /&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt;
  
      &lt;script src="../../jquery-1.9.1.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
  
              if ($("#button").click()) {
                  $("#button", this).prop('disabled', true);
              } else {
                  $("#button", this).prop('disabled', false);
              }
  
          });
      &lt;/script&gt;
  &lt;/h:head&gt;
  
  &lt;h:body&gt;
      &lt;h:form id="form1" enctype="multipart/form-data" prependId="false"&gt;
  
          &lt;p:commandButton id="button" type="submit" value="Submit"
              action="#{pc_Ma1009.doSubmitAction}" ajax="false"&gt;&lt;/p:commandButton&gt;
  
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>