title: Can I condition an specific js event in an if statement?
body: <p>I have an edit in place function, which needs to save the new value when the element loses focus. The thing is these are elements in a table, so each one of them has the element id followed by the id they have in the database, and that's why I couldn't just use <code>$('#id').on('event', function(){}</code>.</p>
  <p>The element looks something like this:</p>
  <pre><code>&lt;td&gt;
  &lt;div id=&quot;quant&lt;?php echo $id_product; ?&gt;&quot; 
  onclick=&quot;live_update('&lt;?php echo $id_product; ?&gt;')&quot;&gt;
  
       &lt;?php echo $quantity;?&gt;
  
  &lt;/div&gt;
  &lt;/td&gt;
  </code></pre>
  <p>and the js looks something like this:</p>
  <pre><code>function live_update(id){
      
      var quantity = $('#quant'+id).text().trim();
      
      $('#quant'+id).html('');
      $('&lt;input&gt;&lt;/input&gt;')
          .attr({
              'type': 'text',
              'name': 'name_quant'+id,
              'id': 'id_quant'+id,
              'size': '5',
              'value': quantity,
              'minlength' : '1',
              'maxlength' : 4
          })
          .appendTo('#quant'+id);
      $('#id_quant'+id).focus();
  }
  </code></pre>
  <p>So far so good, the thing is I now need to update that specific element when the newly generated input loses focus, so I need to pass not only it's html id, but it's database id too, so I can't just use <code>$('#id_quant').on('blur', function(){}</code> because it won't know which element in the table to listen.</p>
  <p>So I figured I would call another function just like this one when the new input loses focus, but I'm not sure if I can do that, and I don't know how the syntax would be.
  In my mind it looks like this:</p>
  <pre><code>if($('#id_quant'+id).blur){ function ajax_update(id) }
  </code></pre>
  <p>or</p>
  <pre><code>if($(blur('#id_quant'+id))){ function ajax_update(id) }
  </code></pre>
  <p>I'm not really sure I can do that though.</p>