Skip to content

Commit

Permalink
Merge pull request #189 from TeerthTejani26/simple-html-template-element
Browse files Browse the repository at this point in the history
Add new HTML Template Element example with header and footer
  • Loading branch information
samdutton authored Aug 8, 2024
2 parents 68ac5a8 + 47768a9 commit aaf97b7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
<a href="stt" title="Web Speech API: speech to text">speech recognition</a>
<a href="tts" title="Web Speech API: text to speech">speech synthesis</a>
<a href="svg" title="SVG example">SVG</a>
<a href="template" title="HTML Template Element">&lt;template&gt;</a>
<a href="track" title="Track element">&lt;track&gt; with &lt;video&gt;</a>
<a href="track/audio" title="Track element for audio">&lt;track&gt; with &lt;audio&gt;</a>
<a href="track/map" title="Track element with synchronised metadata">&lt;track&gt; to synchronise video playback with Google Maps &amp; Street View display</a>
Expand Down
28 changes: 28 additions & 0 deletions template/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Styles for HTML Template Example */
#itemList {
list-style-type: none;
padding: 0;
}

#itemList li {
background-color: #f0f0f0;
margin-bottom: 5px;
padding: 10px;
}

header, footer {
border-bottom: 1px solid #eee;
margin-bottom: 20px;
padding-bottom: 10px;
text-align: center;
}

footer {
border-top: 1px solid #eee;
margin-top: 20px;
padding-top: 10px;
}

h1 {
font-size: 24px;
}
38 changes: 38 additions & 0 deletions template/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>

<html lang="en">

<head>
<title>HTML Template Element</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/main.css">
<script src="js/main.js" defer></script>
</head>

<body>
<div id="container">
<header>
<h1><a href="https://simpl.info">simpl.info </a>HTML.Template.Element</h1>
</header>

<main>
<p>This example demonstrates how to use the HTML <code>&lt;template&gt;</code> element.</p>

<button id="add">Add Item</button>

<ul id="itemList"></ul>

<template id="itemTemplate">
<li>Item</li>
</template>
</main>

<footer>
<a href="https://github.com/samdutton/simpl/blob/master/template/index.html" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>
</footer>

</div>
</body>

</html>
11 changes: 11 additions & 0 deletions template/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
document.addEventListener('DOMContentLoaded', () => {
const addButton = document.getElementById('add');
const itemList = document.getElementById('itemList');
const itemTemplate = document.getElementById('itemTemplate').content;

addButton.addEventListener('click', () => {
const newItem = itemTemplate.cloneNode(true);
itemList.appendChild(newItem);
});
});

0 comments on commit aaf97b7

Please sign in to comment.