-
Notifications
You must be signed in to change notification settings - Fork 0
/
testEvents.html
43 lines (33 loc) · 1.16 KB
/
testEvents.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
<html>
<head>
<script type="text/javascript">
function handler(eventName) {
// create an new element
var para = document.createElement('p');
// it is the same with 1st way
para.innerText = eventName;
// access parent element
var parent = document.getElementsByTagName('body')[0];
// find the element need to replace
var need2Replace = document.getElementsByTagName('p')[1];
// replace the element
if (need2Replace === undefined) {
parent.appendChild(para);
} else {
parent.replaceChild(para, need2Replace);
}
}
function getValue() {
var retVal = prompt("Enter your name : ", "your name here");
document.write("You have entered : " + retVal);
}
</script>
</head>
<body>
<p>Bring your mouse inside the division to see the result:</p>
<div onmouseover="handler('over')" onmouseout="handler('out')">
<h2> This is inside the division </h2>
<button onclick="getValue()">Click here!</button>
</div>
</body>
</html>