Skip to content

Commit 0bd0a01

Browse files
committed
Finished module 5
1 parent 41a9d0b commit 0bd0a01

File tree

4 files changed

+74
-25
lines changed

4 files changed

+74
-25
lines changed

exercises/29 - Events/events1.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<button class="butts">Click me!</button>
11+
<button class="cool">Click me also!</button>
12+
13+
<h2>Buy Buttons</h2>
14+
15+
<button class="buy">Buy Item 1</button>
16+
<button class="buy">Buy Item 2</button>
17+
<button class="buy">Buy Item 3</button>
18+
<button class="buy">Buy Item 4</button>
19+
<button class="buy">Buy Item 5</button>
20+
<button class="buy">Buy Item 6</button>
21+
<button class="buy">Buy Item 7</button>
22+
<button class="buy">Buy Item 8</button>
23+
<button class="buy">Buy Item 9</button>
24+
<button class="buy">Buy Item 10</button>
25+
26+
<script src="./events1.js"></script>
27+
</body>
28+
</html>

exercises/29 - Events/events1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const butts = document.querySelector('.butts');
2+
const coolButton = document.querySelector('.cool');
3+
4+
const buyButtons = document.querySelectorAll('button.buy');
5+
6+
const handleClick = event => {
7+
console.log(event);
8+
};
9+
10+
butts.addEventListener('click', handleClick);
11+
coolButton.addEventListener('click', handleClick);
12+
13+
buyButtons.forEach(element => {
14+
console.log(element);
15+
element.addEventListener('click', handleClick);
16+
});

exercises/29 - Events/forms.html

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
6+
<title>HTML Forms</title>
7+
<link rel="stylesheet" href="../../base.css" />
8+
</head>
39

4-
<head>
5-
<meta charset="UTF-8">
6-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<title>HTML Forms</title>
8-
<link rel="stylesheet" href="../../base.css">
9-
</head>
10-
11-
<body>
12-
<div class="wrapper">
13-
<a class="wes" href="https://wesbos.com">Wes Bos</a>
14-
<form name="signup">
15-
<label for="name">Name</label>
16-
<input type="text" id="name" name="name" value="Wes Bos">
17-
<label for="email">Email</label>
18-
<input type="email" id="email" name="email" value="[email protected]">
19-
<input type="checkbox" id="agree" name="agree">
20-
<label for="agree">I agree to the terms and conditions</label>
21-
<hr>
22-
<button type="submit">Submit</button>
23-
</form>
24-
</div>
25-
26-
27-
<script src="./forms.js"></script>
28-
</body>
10+
<body>
11+
<div class="wrapper">
12+
<a class="wes" href="https://wesbos.com">Wes Bos</a>
13+
<form name="signup">
14+
<label for="name">Name</label>
15+
<input type="text" id="name" name="name" value="Wes Bos" />
16+
<label for="email">Email</label>
17+
<input type="email" id="email" name="email" value="[email protected]" />
18+
<input type="checkbox" id="agree" name="agree" />
19+
<label for="agree">I agree to the terms and conditions</label>
20+
<hr />
21+
<button type="submit">Submit</button>
22+
</form>
23+
</div>
2924

25+
<script src="./forms.js"></script>
26+
</body>
3027
</html>

exercises/29 - Events/forms.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
console.log('it works');
2+
3+
const signupForm = document.querySelector('[name="signup"]');
4+
5+
signupForm.addEventListener('submit', event => {
6+
event.preventDefault();
7+
const name = event.currentTarget.name.value;
8+
});

0 commit comments

Comments
 (0)