title: Jquery Click Event Not Firing On First Click, but does on second click, why?
body: <p>I've got a jQuery code, which</p>
  <pre><code>$(&quot;a.reply&quot;).click(function() {
  //code
  });
  </code></pre>
  <p>When I click the  link with <code>.reply</code> class the first time, nothing happens.  The second time I click, the code inside the click function works.</p>
  <p>The link is being inserted on the page using PHP from a mysql database.  so it's not being inserted dynamically.</p>
  <p>Why is this happening?  Any solution?</p>
  <p><strong>The BadASS Code:</strong></p>
  <pre><code>$(function(){
  //TextArea Max Width
  var textmaxwidth = $('#wrapper').css('width');
  //Initialize Focus ids To Different Initially
  var oldcommentid = -1;
  var newcommentid = -2;
  //End Of initialization
  
  $(&quot;a.reply&quot;).click(function() {
          newcommentid = $(this).attr('id');
          if (newcommentid == oldcommentid)
          {
          oldcommentid=newcommentid;
          $(&quot;#comment_body&quot;).focus();
          }
          else
          {
          $('#comment_form').fadeOut(0, function(){$(this).remove()});
          var commetformcode = $('&lt;form id=&quot;comment_form&quot; action=&quot;post_comment.php&quot; method=&quot;post&quot;&gt;&lt;textarea name=&quot;comment_body&quot; id=&quot;comment_body&quot; class=&quot;added_comment_body&quot; rows=&quot;2&quot;&gt;&lt;/textarea&gt; &lt;input type=&quot;hidden&quot; name=&quot;parent_id&quot; id=&quot;parent_id&quot; value=&quot;0&quot;/&gt; &lt;div id=&quot;submit_button&quot;&gt; &lt;input type=&quot;submit&quot; value=&quot;Share&quot;/&gt;&lt;input type=&quot;button&quot; id=&quot;cancelbutton&quot; value=&quot;Cancel&quot;/&gt;&lt;/div&gt;&lt;/form&gt;');
          commetformcode.hide().insertAfter($(this)).fadeIn(300);
          //
          var id = $(this).attr(&quot;id&quot;);
          $(&quot;#parent_id&quot;).attr(&quot;value&quot;, id);
          oldcommentid=newcommentid;
          //dynamicformcreation function
          dynarun();
          //
          }
  
  
  
          return false;
      });
  
          dynarun();
          
          function dynarun()
          {
          //Form Re-Run Functions
          $('#comment_body').elastic();
          texthover();
          $(&quot;#comment_form input, select, button&quot;).uniform();
          textareasizer();
          $(&quot;#comment_body&quot;).focus();
          $(&quot;abbr.timestamp&quot;).timeago();
          return false;
          }
          
          //TextArea Resizer Function
          function textareasizer(){$(&quot;#comment_body&quot;).css('max-width', textmaxwidth);return false;}
          
          //Other Miscellaneous Functions
          $('.comment-holder').hover(
          function(event) {
              $(this).addClass('highlight');
          },
          function(event) {
              $('.comment-holder').removeClass('highlight');
          }
          );
  
          function texthover()
          {
          $('.added_comment_body').hover(
              function(event) {
                  $(this).parent().parent().addClass('highlight');
              },
              function(event) {
                  $('.comment-holder').removeClass('highlight');
              }
          );
          return false;
          }
  });
  </code></pre>