How to find if div with specific id exists in jQuery

How to find if div with specific id exists in jQuery

I have this code:
  1. $('body').on('click', '#materials li', function () {
  2. if($(".appended").length == 0){

  3. $('#materials-form').append('<input type="hidden" class ="appended" name ="Materials[' + $(this).attr('data-id') + ']" value="' + $(this).attr('data-supplier') + '"/>');
  4. $('#materials-form').append('<li>' + $(this).text() + '<button data-id = "' + $(this).attr('data-id') + '">Delete</button>' + '<input type ="text" id = "quantity" name="quantity[' + $(this).attr('data-id') + ']" /> ' + '<input type ="hidden" id="price" name="price[' + $(this).attr('data-id') + ']" value ="' + $(this).attr('data-price') + '"' + '</li>');


  5. $("#quantity").keyup(function () {
  6. var sVal = this.value;
  7. var iNum = parseInt(sVal);
  8. var price = $("#price").val();
  9. //var price_num = parseInt(price);
  10. //alert(price);
  11. var total = iNum * price;
  12. $('#materials-form').append('<li>' + total + '</li>');
  13. alert((total));
  14. });


  15. } else { console.log("exist");
When only one record exists it works fine because it is only one record. The problem is when there are many records and it checks only one. 

The question is , how in here:  if($(".appended").length == 0){, to check the specific li?