I have this code:
$.ajax({
url: "ajax-ongkir.php?destination=" + subdistrictId + "&destination_type=subdistrict&weight=" + weight,
dataType: "JSON",
success: function(json) {
for (var i = 0; i < json.length; i++) {
var courierName = json[i].name;
var courierService = json[i].service;
var courierTarif = json[i].tarif;
$('.courier').append($('<option>', {
value: courierName + ' ' + courierService + ' ' + courierTarif,
text: courierName + ' - ' + courierService + ' - ' + courierTarif
}));
$('.courier').$('<option>').last().attr('data-tarif', courierTarif);
}
}
});
but this line doesn't work:
$('.courier').$('<option>').last().attr('data-tarif', courierTarif);
How to add courierTarif as data attribute into <option>?