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