Platform
Resources
Pricing
Sign in
Get started
Andrew Wooldridge
📜JavaScript developer. 🐲RPG fan. 📚Storyteller and 🕹game developer. 👨Father and Husband.
Workspace
Fork
Published
By
Andrew Wooldridge
Edited
Jul 29, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
html_main
;
// make sure HTML is defined for Observable foo.
// selecting the :root theme
const
root_theme
=
document
.
querySelector
(
':root'
)
;
// seleting the button which will trigger the event
const
root_btn
=
document
.
querySelector
(
'.btn-css-v'
)
;
// the event listener to change the text color upon 'click'
root_btn
.
addEventListener
(
'click'
,
(
)
=>
{
// changing the color from #0b32e7 to #f44336
root_theme
.
style
.
setProperty
(
'--demo-color-change'
,
'#f44336'
)
;
}
)
;
}
Insert cell
Insert cell
viewof
color
=
Inputs
.
color
(
{
label
:
"Favorite color"
,
value
:
"#4682b4"
}
)
Insert cell
html_color
=
html
`<button>click here</button> to change the text color.`
Insert cell
changeColor
=
(
)
=>
{
console
.
log
(
'changeColor called'
)
document
.
querySelector
(
':root'
)
.
style
.
setProperty
(
'--demo-color-change'
,
color
)
}
Insert cell
{
html_color
.
querySelector
(
'button'
)
.
addEventListener
(
'click'
,
changeColor
)
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
html_main
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
html_color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
changeColor
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML