-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (43 loc) · 1.49 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$.ajax({
url: "cars.json",
dataType: "json",
success: function (data) {
var carTable = $("#carTable tbody");
var allCars = data.cars;
$.each(allCars, function (index, car) {
var row = $("<tr>");
row.append(
$("<td>").html(
'<img src="./assets/' + car.model + '.jpg" class="car-img">'
)
);
row.append($("<td>").text(car.brand));
row.append($("<td>").text(car.model));
row.append($("<td>").text(car.model_year));
row.append($("<td>").text(car.mileage));
row.append($("<td>").text(car.fuel_type));
row.append($("<td>").text(car.seats));
row.append($("<td>").text(car.price_per_day));
row.append(
$("<td>").text(car.availability ? "Available" : "Not Available")
);
row.append($("<td>").text(car.description));
var addToCartButton = $("<button class='addToCartButton'>Add to Cart</button>");
if (!car.availability) {
addToCartButton.prop("disabled", true);
addToCartButton.css("background-color", "#ccc");
addToCartButton.css("cursor", "not-allowed");
}
row.append($("<td>").append(addToCartButton));
carTable.append(row);
});
}
});
$(document).ready(function() {
$('#search').on('keyup', function() {
var value = $(this).val().toLowerCase();
$('#carTable tbody tr').filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});