Pen Settings



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


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


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.


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.


                <div class="twocol">
		<table id="contactsTable">
					<th>Last Name</th>
					<th>First Name</th>
			<input type="hidden" id="key">
			<label>First Name <input type="text" id="firstname"></label><br/>
			<label>Last Name <input type="text" id="lastname"></label><br/>
			<label>Email <input type="email" id="email"></label><br/>
			<button id="saveBtn">Save</button>


                .twocol {
	display: grid;
	grid-template-columns: 50% 50%;

table {
	border-collapse: collapse;
	border: 1px solid black;
	width: 100%;
	max-width: 500px;

th, td {
	border: 1px solid black;
	padding: 5px;	


                document.addEventListener('DOMContentLoaded', init, false);

let $saveBtn, $firstname, $lastname, $email, $key, $table;
let db;

async function init() {
	db = await initDb();
	$saveBtn = document.querySelector('#saveBtn');
	$saveBtn.addEventListener('click', saveContact, false);
	$firstname = document.querySelector('#firstname');
	$lastname = document.querySelector('#lastname');
	$email = document.querySelector('#email');
	$key = document.querySelector('#key');
	$table = document.querySelector('#contactsTable tbody');

// TODO: Validation
async function saveContact(e) {

	let contact = {
		firstname: $firstname.value,
		lastname: $lastname.value, 
		email: $email.value
	if($key.value) = parseInt($key.value,10);
	await persistContact(contact);
	$firstname.value = '';
	$lastname.value = '';
	$email.value = '';
	$key.value = '';

async function renderContacts() {
	let contacts = await getContacts();
	let s = '';
	contacts.forEach(c => {
			s += `
			<td><button data-key="${}" class="edit">Edit</button> <button data-key="${}" class="delete">Delete</button></td>
	$table.innerHTML = s;

	let buttons = document.querySelectorAll('td button.edit');
	buttons.forEach(b => {
		b.addEventListener('click', editContact, false);
	buttons = document.querySelectorAll('td button.delete');
	buttons.forEach(b => {
		b.addEventListener('click', deleteContact, false);

async function editContact(e) {
	let key = parseInt(,10);
	let contact = await getContact(key);
	$firstname.value = contact.firstname;
	$lastname.value = contact.lastname;
	$email.value =
	$key.value =;

async function deleteContact(e) {
	let key = parseInt(,10);
	await removeContact(key);	

I create the db, the store, and the index. When done, I return the db
async function initDb() {
	let db = new Dexie('contacts_dexie');
	return db;	

async function persistContact(contact) {
	await db.contacts.put(contact);

async function getContacts() {
	return await db.contacts.toArray();

async function removeContact(key) {
	return await db.contacts.delete(key);

async function getContact(key) {
	return await db.contacts.get(key);