title: What does on() in JavaScript do?
body: <p>I am performing some crude operations in PHP without refreshing the page.</p>
  
  <p>I don't understand this <code>on()</code> function, what does it do? And what is the parameter <code>#add</code> doing here?</p>
  
  <pre class="lang-javascript prettyprint-override"><code>$(document).on('click','#add',function(){
      var name = $('#name').text();   //name &amp; lname-table attribut names 
      var lname= $('#lname').text();
      if(name =='')
      {
          alert("Enter name");
          return false;
      }    
      if (lname=='')
      {
          alert("Enter last name");
          return false;
      }
  })
  </code></pre>