title: jquery add element if not present
body: <p>I'm reading a book on jQuery and it has some simple tasks and examples.</p>
  
  <p>I'm trying out the adding of an element to a table, but only if the item is not yet present.</p>
  
  <p>The table is this:</p>
  
  <pre><code>&lt;table border="1" cellspacing="0"&gt;
    &lt;tr&gt;
      &lt;td&gt;Spaghetti&lt;/td&gt;
      &lt;td&gt;Karl&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Pasta&lt;/td&gt;
      &lt;td&gt;David&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The problem is: we're not allowed to add any classes or id's.</p>
  
  <p>The idea is to add a caption. And of course, if the button is pressed 2 times, no second caption is added.</p>
  
  <p>I tried this:</p>
  
  <pre><code>if(!jQuery.contains('table','caption')) {
      $('table').append('&lt;caption&gt;Orders&lt;/caption&gt;');
  }
  </code></pre>
  
  <p>And this</p>
  
  <pre><code>if(!($("table:contains('caption')"))) {
      $('table').append('&lt;caption&gt;Orders&lt;/caption&gt;');
  }
  </code></pre>
  
  <p>But neither work. I've read the jQuery api on the functions and selectors, I thought these would work but they don't. What do I need to do?</p>