-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="./main.css" /> | ||
</head> | ||
<body> | ||
|
||
<h1> | ||
HTML Templates Can Be Mutated Just Like Any Other DOM | ||
</h1> | ||
|
||
<div x-data="{ isShowing: false }"> | ||
|
||
<button @click="( isShowing = ! isShowing )"> | ||
Toggle Template | ||
</button> | ||
|
||
<template x-if="isShowing" class="counter-template"> | ||
<p> | ||
Counter: <strong class="counter">0</strong> | ||
</p> | ||
</template> | ||
|
||
</div> | ||
|
||
<script type="text/javascript" src="../../vendor/alpine/3.13.5/alpine.3.13.5.js" defer></script> | ||
<script type="text/javascript"> | ||
|
||
var counter = 0; | ||
|
||
// Update the contents of the template every second. | ||
setInterval( | ||
() => { | ||
|
||
var target = document.querySelector( ".counter-template" ) | ||
// The template contents represent a detached document fragment that | ||
// provides its own DOM that can be inspected using querySelector(). | ||
.content | ||
.querySelector( ".counter" ) | ||
; | ||
|
||
target.innerText = ++counter; | ||
|
||
}, | ||
1000 | ||
); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body, | ||
button { | ||
font-family: monospace ; | ||
} |