script.js 1.42 KB
Newer Older
1 2
console.log("script say hi!");

3 4 5 6 7 8 9 10 11 12 13 14
let items = document.querySelectorAll("input");

items.forEach(function(checkBox){
	checkBox.checked = false;
});


function addEventListenerList(list, event, fn) {
    for (var i = 0, len = list.length; i < len; i++) {
        list[i].addEventListener(event, fn, false);
    }
}
15 16


17 18 19 20 21 22 23
function getItemState (item) {

	if (item.checked) {
		return true;
	} else {
		return false;
	}
24 25 26 27
}


function displayItem() {
28 29
   	let selectItem = document.querySelector('#' + this.id);
    let toChange = selectItem.parentElement.classList;
30

31 32 33
    if (getItemState(this) && toChange.contains("noprint")) {
		toChange.remove("noprint");
	} else if (!getItemState(this)) {
34
		toChange.add("noprint");
35
	}
36 37 38
}


39 40 41 42
addEventListenerList(items, 'click', displayItem);



43
/* PLUS BUTTON */
44 45 46 47
let plusBt = document.querySelectorAll('.plusBt');

function incrementQuantity() {
	console.log(this);
48 49
	let qtyValue = Number(this.previousElementSibling.innerHTML);
	this.previousElementSibling.innerHTML = qtyValue + 1;
50 51
}

52 53 54 55 56 57 58 59
addEventListenerList(plusBt, 'click', incrementQuantity);


/* MINUS BUTTON */
let minusBt = document.querySelectorAll('.minusBt');

function decrementQuantity() {
	console.log(this);
60 61 62 63 64
	let qtyValue = Number(this.previousElementSibling.previousElementSibling.innerHTML); 
	if (qtyValue > 1) {
		this.previousElementSibling.previousElementSibling.innerHTML = qtyValue - 1;
	}
	
65 66 67
}

addEventListenerList(minusBt, 'click', decrementQuantity);