/
js-receips-html
60 lines (41 loc) · 1.18 KB
/
js-receips-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
1. Add an element to the page
a) Does the element have a content?
b) Are there any attributes that need to be set?
c) Where does it go?
2. Adding behavior to an element
a) What element?
b) What function?
3.Changing somenthing about an existing element
a) Which element?
b) What are you changing?
4. Go get data from a server
-ajax(?)
5. Given a set of things, do somenthing to each of them
-loops (?)
<script>
//adding an element to the page
// 1. create the element
var child = document.createElement("li");
// 2. append the element to some element that is already there
var parent = document.querySelectors("ul");
parent.appendChild(child);
// 3. setting the content
child.setAttribute("class", "todo-item");
//yields
//<ul>
// <li class="todo-item"> Do my homework...</li>
// </lu>
//adding behavior to an element
var button = document.querySelector("#click-me");
function sayCursorLocation(clickEvent)
//this is just an example, you can do whatever you"d like.
{
var x =clickEvent.clientX;
var y = clickEvent.clientY;
alert("your mouse is at: "+ x +"," + y);
}
// 3. attaching the event handler
var
}
document.createElement("li")
</script>