Skip to content

Commit 38a6c77

Browse files
committed
events intro
1 parent 9f9101b commit 38a6c77

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

eventsInJS/index.html

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
<title>Document</title>
7+
</head>
8+
<body style="background-color: #414141; color: aliceblue;">
9+
<h1>Amazing image</h1>
10+
<div>
11+
<ul id="images">
12+
<li><img width="200px" id="photoshop" src="https://images.pexels.com/photos/2244330/pexels-photo-2244330.jpeg?auto=compress&cs=tinysrgb&w=600" alt="photoshop"></li>
13+
<li><img width="200px" id="japan" src="https://images.pexels.com/photos/402028/pexels-photo-402028.jpeg?auto=compress&cs=tinysrgb&w=600" alt=""></li>
14+
<li><img width="200px" id="river" src="https://images.pexels.com/photos/2189700/pexels-photo-2189700.jpeg?auto=compress&cs=tinysrgb&w=600" alt=""></li>
15+
<li><img width="200px" id="owl" src="https://images.pexels.com/photos/53977/eagle-owl-raptor-falconry-owl-53977.jpeg?auto=compress&cs=tinysrgb&w=600" alt=""></li>
16+
<li><img width="200px" id="prayer" src="https://images.pexels.com/photos/1003917/pexels-photo-1003917.jpeg?auto=compress&cs=tinysrgb&w=600" alt=""></li>
17+
<a style="color: aliceblue;" href="https://google.com" id="google">Google</a>
18+
</ul>
19+
</div>
20+
</body>
21+
<script>
22+
// document.getElementById('owl').onclick = function() {
23+
// alert('owl clicked')
24+
// }
25+
// attachEvent()
26+
// jQuery - on
27+
// type, timestamp, preventDefault
28+
// target, toElement, srcElement, currentTarget
29+
// clientX, clientY, screenX, screenY
30+
// altkey, ctrlkey, shiftkey, keyCode
31+
32+
/*
33+
document.getElementById('images').addEventListener('click', function(e){
34+
console.log('clicked inside the ul')
35+
}, false)
36+
document.getElementById('owl').addEventListener('click', function(e){
37+
console.log('owl clicked')
38+
e.stopPropagation()
39+
}, false)
40+
41+
document.getElementById('google').addEventListener('click', function(e){
42+
e.preventDefault()
43+
e.stopPropagation()
44+
console.log('google clicked')
45+
}, false)
46+
*/
47+
48+
document.querySelector('#images').addEventListener('click', function(e){
49+
console.log(e.target.parentNode);
50+
if (e.target.tagName === 'IMG') {
51+
console.log(e.target.id);
52+
let removeIt = e.target.parentNode
53+
removeIt.remove()
54+
//removeIt.parentNode.removeChild(removeIt)
55+
}
56+
})
57+
</script>
58+
</html>

0 commit comments

Comments
 (0)