-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
72 lines (72 loc) · 3.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Tutorial Lesson one.1 – Solution #1</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>jQuery Tutorial Lesson one.1 – Solution #1</h1>
<h2>
<a href="https://github.com/mulithemuli/jquery-tutorial#lesson-1--attaching-the-event-handlers" target="_blank">Attaching the event handlers</a>
</h2>
<h3>Comes in handy</h3>
<ul class="collection">
<li class="collection-item"><a href="https://github.com/mulithemuli/jquery-tutorial#functions-and-arrow-functions" target="_blank">Preflight / functions and arrow functions</a></li>
<li class="collection-item"><a href="https://github.com/mulithemuli/jquery-tutorial#event-handlers" target="_blank">Preflight / Event handlers</a></li>
</ul>
<p>Write a script with jQuery which takes the entered text and prints it in a span below on button click.</p>
<h3>Covered in this Lesson</h3>
<ul class="collection">
<li class="collection-item">jQuery Selectors</li>
<li class="collection-item">jQuery Event handling</li>
<li class="collection-item">basic DOM manipulation</li>
</ul>
<blockquote>
It is allowed to add tags, IDs or classes. Although the existing ones must be preserved. The solution is
possible without doing that.
</blockquote>
<h3>Solution</h3>
<p>
<a href="https://codepen.io/mulithemuli/pen/yLBaMem" target="_blank">on CodePen</a>
</p>
<form>
<div class="row">
<div class="input-field col s12">
<input id="text_1" type="text">
<label for="text_1">Text #1</label>
<span id="helper_text_1" class="helper-text"></span>
<button id="text_1_handler" class="btn waves-effect waves-light" type="button">Show Text #1</button>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="text_2" type="text">
<label for="text_2">Text #2</label>
<span id="helper_text_2" class="helper-text"></span>
<button id="text_2_handler" class="btn waves-effect waves-light" type="button">Show Text #2</button>
</div>
</div>
</form>
<h3>Thoughts on the solution</h3>
<p>
This solution uses hardcoded IDs which works but is not very generic. What if a third input should be added which covers the same functionality as one and two?
</p>
<ul class="collection">
<li class="collection-header">
<h4>What have we done to make it work?</h4>
</li>
<li class="collection-item">Added an id to the button</li>
<li class="collection-item">Added an id to the helper-text span</li>
<li class="collection-item">Attaching the event handler to each of the buttons separately</li>
<li class="collection-item">Fetching the value of the input in each of the handler functions separately</li>
<li class="collection-item">Writing the value to the <code>span.helper-text</code> by each id</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js" integrity="sha384-ZOED+d9HxogEQwD+jFvux96iGQR9TxfJO+mPF2ZS0TuKH6eWrmvPsDpO6I0OWdiX" crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>