Shopping List App
Generic shopping list application
by kdowdell24
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping List</title>
<link rel="stylesheet" href="css/shopping_list.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Mali:400,700" rel="stylesheet">
</head>
<body>
<main>
<header>
<button type="button" id="add-button">
<i class="far fa-plus-square"></i>
</button>
<h1>Shopping List</h1>
</header>
<section>
<form onsubmit="return false" id="shopping-list">
</form>
</section>
<footer>
<button type="button" id="clear-button">Clear All</button>
</footer>
</main>
<script src="js/shopping_list.js"></script>
</body>
</html>
CSS
/********media queries******/
@media only screen and (max-width: 480px) {
html body main {
width: 80%;
}
form div input[type="text"] {
width: 55%;
}
form div .check-box:checked:after {
font-size: 10px;
}
}
@media only screen and (max-width: 1024px) {
body main {
width: 40%;
}
div input[type="text"] {
width: 55%;
}
div .check-box:checked:after {
font-size: 10px;
}
}
/***************************/
*, *::before, *::after {
box-sizing: border-box;
}
html {
margin: 0;
}
body {
background-color: #d1c6bf;
}
main {
margin: 4em auto;
width: 30%;
box-shadow: 0.1em 0.1em 2em black;
border-radius: 0.5em;
border: 0.5em solid #474c52;
}
header {
background-color: #474c52;
color: white;
padding: 0.5em;
}
h1 {
font-family: 'Mali', cursive;
font-size: 2em;
text-align: center;
margin-left: 0.5em;
display: inline;
clear: left;
}
section {
background-color: #c9cbcf;
height: 20em;
overflow: auto;
}
#add-button {
font-size: 2em;
border: none;
padding: 0;
color: white;
background: none;
display: inline;
float: left;
}
#add-button:hover {
color: #acb3b9;
transition: 0.2s;
}
.input-item {
margin-bottom: 0.5em;
background-color: #aeb1b7;
}
input[type="text"] {
border: none;
background: none;
font-family: 'Mali', cursive;
font-size: 1em;
width: 75%;
margin: 0 auto;
display: inline-block;
}
.check-box {
-webkit-appearance: none;
margin-left: 1em;
height: 2em;
width: 2em;
border: 0.2em solid #474c52;
border-radius: 0.2em;
display: inline-block;
position: relative;
}
.check-box:checked:after {
content: '\2714';
font-size: 1rem;
font-weight: bold;
position: absolute;
top: 0px;
left: 3px;
color: #474c52;
background-color: none;
}
.delete-button {
font-size: 2em;
border: none;
background: none;
color: #93979f;
margin: none;
display: inline-block;
}
.delete-button:hover {
color: #484b51;
transition: 0.2s;
}
footer...
JavaScript
document.getElementById("add-button").addEventListener("click", function() {
function createNewItem() {
//creates div element with a class of "input-item"
let itemContainer = document.createElement("div");
itemContainer.classList.add("input-item");
//creates input element and sets type attribute to "checkbox"
let checkBoxInput = document.createElement("input");
checkBoxInput.setAttribute("type", "checkbox");
checkBoxInput.classList.add("check-box");
//creates input element and sets "type" attribute to "text"
let textInput = document.createElement("input");
textInput.setAttribute("type", "text");
//creates button element and sets "class" to "delete-button" and "type" to "button"
let deleteButton = document.createElement("button");
deleteButton.classList.add("delete-button");
deleteButton.setAttribute("type", "button");
//creates Font Awesome "X" icon and adds "fas" and "fa-times" classes
let xIcon = document.createElement("i");
xIcon.classList.add("fas");
xIcon.classList.add("fa-times");
//adds a div form
let formElement = document.getElementById("shopping-list");
formElement.appendChild(itemContainer);
//adds input and "delete-button" to div
itemContainer.appendChild(checkBoxInput);
itemContainer.appendChild(textInput);
itemContainer.appendChild(deleteButton);
//adds "X" icon to button
deleteButton.appendChild(xIcon);
//removes an input and deleteButton from form
deleteButton.addEventListener("click", function() {
checkBoxInput.remove();
textInput.remove();
deleteButton.remove();
itemContainer.remove();
});
};
createNewItem();
//Adds new item after pressing Enter key
let itemList = document.querySelectorAll("input[type=text]");
for (var i = 0;...