title: Check if an ID exists or not using jQuery
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7227087/finding-whether-the-element-exists-in-whole-html-page">Finding whether the element exists in whole html page</a>  </p>
  </blockquote>
  
  
  
  <p>Is there any way to check for if a ID $('#ID') exists in jQuery</p>
  
  <p>Ex: </p>
  
  <p><code>$('#cart').append('&lt;li id="456"&gt;My Product&lt;/li&gt;');</code></p>
  
  <p>After running append() to something like this I want to check if my ID $('#456') exists or not. If it exits I want to change the text, else I want to append a new <li>.</p>
  
  <pre><code>$(document).ready(function() {
          $('#RAM,#HDD').change(function() {
  
              var product = $(this).find("option:selected").attr("product");
  
              $.ajax({
                  url: 'ajax.php',
                  type: 'post',
                  data: $(this).serialize(),
                  dataType: 'json',
                  success: function(data) {
                      $('#cart').empty();
                      $.each(data, function(index, value) {
                          $('#cart').append('&lt;li id="'+product+'"&gt;'+ value['price'] +'&lt;/li&gt;');
                      });
                  }
              });
          });
      });
  </code></pre>