Possible duplicate:
Finding if an element exists throughout the html page
Is there a way to check if ID $ ('# ID') exists in jQuery
Example:
$('#cart').append('<li id="456">My Product</li>');
After running append () for something like this, I want to check if my ID $ ('# 456') exists. If it comes out, I want to change the text, otherwise I want to add a new one
.
$(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('<li id="'+product+'">'+ value['price'] +'</li>'); }); } }); }); });
stackminu
source share