$(document).on("click", ".is-default", function() { var value = $(this).html(); var new_value = 'Y'; var rnum = $(this).attr('rnum'); var spanID = $(this); if (value == 'Y') new_value = 'N'; var data = "table_name=staff_categories"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&is_default="+new_value; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(new_value); } ); });