Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
<head>
	<title>Javascript + DOM</title>
	<link href="https://fonts.googleapis.com/css?family=BioRhyme:300|Monoton" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
	<div class="container">
		<div class="header">
			<h1>Shopping List</h1>
			<p id="first">Get it done today!</p>
		</div>
		<div class="list">
			<div class="list--header">
				<input id="userinput" type="text" placeholder="...">
				<button id="enter">Enter!</button>
			</div>
			<ul id="item--List">
        <li><span>Chocolate</span>
          <button class="delete--button">Delete</button>
        </li>
        <li><span>Fairy Bread</span>
          <button class="delete--button">Delete</button>
        </li>
				<li><span>Balloons</span>
          <button class="delete--button">Delete</button>
        </li>
        <li><span>Sausages</span>
          <button class="delete--button">Delete</button>
        </li>
        <li><span>Birthday Cake</span>
          <button class="delete--button">Delete</button>
        </li>
				<li><span>Candles</span>
          <button class="delete--button">Delete</button>
        </li>
			</ul>
		</div>
		<div class="footer">Made by Moody</div>
	</div>
	<script type="text/javascript" src="script.js"></script>
</body>
</html>
              
            
!

CSS

              
                /* 
done:
bg image 
new font
containers
style buttons
practise flex/grid
https://images.unsplash.com/photo-1549896869-ca27eeffe4fb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=668&q=80

TO DO:
Media queries!!
*/

html, body {
  margin: auto 0;
  font-size: 18px;
  font-family: 'BioRhyme', serif;
}

body {
  background: 
    url(https://images.unsplash.com/photo-1549896869-ca27eeffe4fb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=668&q=80)
    no-repeat;                 
background-size: cover;
display: grid;
justify-items: center;
}

.container {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50px;
  width: 60vw;
  display: grid;
  justify-items: center;
  grid-gap: 1rem;
  padding: 1rem;
  margin: 2rem 0;
  -webkit-box-shadow: 0 8px 6px -6px rgba(0,0,0,.5);
	-moz-box-shadow: 0 8px 6px -6px rgba(0,0,0,.5);
	box-shadow: 0 8px 6px -6px rgba(0,0,0,.5);
}

.header {
  display: inline-flex;
}

h1 {
  padding: 0 1.5rem;
  font-family: 'Monoton', cursive;
  letter-spacing: 3px;
  font-weight: 300;
  font-size: 2.8em;
}

#first {
  display: flex;
  align-self: baseline;
}

.list {
  background: rgba(247, 192, 192, 0.8);
  border-radius: 20px 100px;
  padding: 2rem;
  width: 30vw;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  -webkit-box-shadow: 0 4px 6px -6px rgba(0,0,0,.5);
	-moz-box-shadow: 0 4px 6px -6px rgba(0,0,0,.5);
	box-shadow: 0 4px 6px -6px rgba(0,0,0,.5);
}

.list--header {
  align-self: center;
  padding-top: 1rem;
}

#userinput, #enter {
  padding: .5rem;
  font-size: .8em;
  border-radius: 5%;
}

#enter {
  background-color: #E15148;
  color: rgba(244, 244, 244, 0.9);
  border: #E15148;
  cursor: pointer;
  margin-top: .5rem;
}

#enter:link,
#enter:visited {
  background-color: #E15148;
  color: rgba(244, 244, 244, 0.9);
  border: #E15148;
}

#enter:hover,
#enter:active {
  background-color: rgba(225, 82, 72, 0.80);
  color: #f4f4f4;
  border: rgba(225, 82, 72, 0.80);
}

ul {
  text-align: right;
  list-style-type: none;
}

li {
  padding-top: .5rem;
  cursor: pointer;
}

button {
  margin-left: 1rem;
  margin-bottom: .5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: .5rem .3rem;
  cursor: pointer;
  border-radius: 30px;
}


.done {
  text-decoration: line-through;
}

.footer {
  font-size: .7em;
  letter-spacing: 1px;
}

              
            
!

JS

              
                var enterButt = document.getElementById("enter");
var input = document.getElementById("userinput");
var ul = document.querySelector("ul");
var listButton = document.querySelectorAll('.delete--button');


function inputLength() {
	return input.value.length;
}

function createListElement(el) {
	var li, inputText, btn;
	li = document.createElement("li");
	inputText = document.createTextNode(input.value);
	btn = document.createElement("button");

	btn.appendChild(document.createTextNode("Delete"));
	li.appendChild(inputText);
	li.appendChild(btn);
	ul.appendChild(li);
	
	input.value = "";
	btn.onclick = deleteListItem;
}

function addListAfterClick() {
	if (inputLength() > 0) {
		createListElement();
	}
}

function addListAfterKeypress(event) {
	if (inputLength() > 0 && event.keyCode === 13) {
		createListElement();
	}
}

function doneItem(e) {
	if (e.target.tagName === "LI") {
		e.target.classList.toggle("done");
	}
}

function deleteListItem(event) {
	var listElement = event.target.parentNode;
	event.target.parentNode.parentNode.removeChild(listElement);
}


enterButt.addEventListener("click", addListAfterClick);

input.addEventListener("keypress", addListAfterKeypress);

ul.addEventListener("click", doneItem);

Array.from(listButton).forEach(link => {
    link.addEventListener('click', deleteListItem);
});


              
            
!
999px

Console