How to find if div with specific id exists in jQuery
I have this code:
- $('body').on('click', '#materials li', function () {
- if($(".appended").length == 0){
- $('#materials-form').append('<input type="hidden" class ="appended" name ="Materials[' + $(this).attr('data-id') + ']" value="' + $(this).attr('data-supplier') + '"/>');
- $('#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>');
- $("#quantity").keyup(function () {
- var sVal = this.value;
- var iNum = parseInt(sVal);
- var price = $("#price").val();
- //var price_num = parseInt(price);
- //alert(price);
- var total = iNum * price;
- $('#materials-form').append('<li>' + total + '</li>');
- alert((total));
- });
- } 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?