I’ve tried to create a simple counter with increase in decrease buttons, but I cannot go any further.
The code I’ve been stuck with is:
for code.gs
let count = 0;
const counter = document.getElementById("count");
function onDec() {
count = count-1;
counter.textContent = count;
}
function onInc() {
count = count+1;
counter.textContent = count;
}
and for index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
</head>
<body>
<div class="container">
<h2><span id="count">0</span></h2>
<button id="decBtn" class="button" onclick="onDec()">-</button>
<button id="incBtn" class="button" onclick="onInc()">+</button>
</div>
</body>
</html>
I’ve realised recently what is missing, is doGet() function in code.gs. But so far adding this didn’t solve the problem. I know I’m missing something simple and important, but I’m completely lost right now.
3
Answers
You do not include in your HTML
You can directly include the html without
include
function like this. This is a working live snippet:You have not included the script in your HTML
In order to execute the script, you need to add a
<script>
element into your HTML document.Notice I’ve modified your filename to
code.js
and I’ve used thedefer
keyword to ensure the code runs after the HTML loads.