FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-DOM/18_function_reference.js at master · last-endcode/JavaScript-DOM · GitHub
last-endcode
/
JavaScript-DOM
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-DOM
/
18_function_reference.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (24 loc) · 796 Bytes
Breadcrumbs
JavaScript-DOM
/
18_function_reference.js
Copy path
File metadata and controls
27 lines (24 loc) · 796 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// select element
// addEventListener
// what event,
// and what to do (callback function/annonymous funciton/function reference)
const
btn
=
document
.
querySelector
(
'.btn'
)
;
const
h3
=
document
.
querySelector
(
'h3'
)
;
// callback as function reference
function
changeColors
(
)
{
let
hasClass
=
h3
.
classList
.
contains
(
'red'
)
;
// first if click join will false and move to else
// second if click again will true and remove class red
// cause h3 has red class
if
(
hasClass
)
{
//false cz no has red class on h3
h3
.
classList
.
remove
(
'red'
)
;
console
.
log
(
hasClass
)
;
}
else
{
// true and add class red on h3
h3
.
classList
.
add
(
'red'
)
;
console
.
log
(
hasClass
)
;
}
}
// remember don't invoking() callback if callback function
btn
.
addEventListener
(
'click'
,
changeColors
)
;
Back
|
FazBrowse Home
|
New Git URL