File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
2024 Prep/machine_coding/vanilla-js/form-validation Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,14 @@ <h1>Form Validation example</h1>
41
41
< button type ="submit " class ="submit-btn "> Submit</ button >
42
42
</ form >
43
43
44
+ < main >
45
+ < h2 > Data attributes</ h2 >
46
+ < ul >
47
+ < li data-animal-type ="bird " onclick ="showDetails(this) "> Owl</ li >
48
+ < li data-animal-type ="insect " onclick ="showDetails(this) "> Ant</ li >
49
+ < li data-animal-type ="fish " onclick ="showDetails(this) "> Gold Fish</ li >
50
+ </ ul >
51
+ </ main >
44
52
< script src ="./script.js "> </ script >
45
53
</ body >
46
54
</ html >
Original file line number Diff line number Diff line change @@ -18,3 +18,10 @@ const onFormSubmit = event => {
18
18
}
19
19
20
20
myForm . addEventListener ( 'submit' , onFormSubmit )
21
+
22
+ function showDetails ( animalType ) {
23
+ const animalTypeVal = animalType . getAttribute ( 'data-animal-type' )
24
+ const animal = animalType . innerHTML
25
+ console . log ( '🚀 ~ showDetails ~ animalType:' , animalTypeVal , animal )
26
+ alert ( `${ animal } is a ${ animalTypeVal } ` )
27
+ }
You can’t perform that action at this time.
0 commit comments