lewtun HF staff commited on
Commit
a6d24ff
1 Parent(s): f830490

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +42 -19
index.html CHANGED
@@ -1,19 +1,42 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Random Chuck Norris Jokes</title>
6
+ <style>
7
+ body{font-family:Arial,sans-serif;text-align:center}
8
+ h1{color:#ff6700;}
9
+ #jokeButton{padding:1rem 2rem;border-radius:.5rem;background-color:#ffcc00;cursor:pointer;transition:opacity.2s ease-in-out}
10
+ #jokeButton:hover{opacity:.9}
11
+ #jokeDisplay{margin-top:2rem;max-width:80%;margin-left:auto;margin-right:auto}
12
+ </style>
13
+ </head>
14
+
15
+ <body>
16
+ <h1>Welcome to Random Chuck Norris Jokes!</h1>
17
+
18
+ <button id="jokeButton">Fetch Joke</button>
19
+ <p id="jokeDisplay"></p>
20
+
21
+ <script>
22
+ // Add listener for button click
23
+ document.getElementById('jokeButton').addEventListener('click', function() {
24
+ // Fetch joke data from endpoint
25
+ fetch("https://api.chucknorris.io/jokes/random")
26
+ .then(function(response){
27
+ return response.json();
28
+ }).then(function(data){
29
+
30
+ var oldJokeNode = document.querySelector("#jokeDisplay");
31
+
32
+ if (oldJokeNode!== null && oldJokeNode.childNodes[0]!= undefined){
33
+ oldJokeNode.replaceChild(document.createTextNode(data.value), oldJokeNode.childNodes[0]);
34
+ } else {
35
+ // No child node exists yet - append text directly
36
+ oldJokeNode.appendChild(document.createTextNode(data.value));
37
+ }
38
+ });
39
+ });
40
+ </script>
41
+ </body>
42
+ </html>