Conteúdo do Curso
Advanced JavaScript Mastery
Advanced JavaScript Mastery
Challenge: Manage Element Properties and Attributes
Task
You're working on a product page where you'll display product information and allow users to toggle the availability status.
Set product name to
"Smartphone"
;Set the initial price to
"499.99"
;Toggle Availability Status Using Attributes : When the button is clicked:
Check if the
<button>
has the attributedata-available
;If
data-available
is present, remove it and update the text content to"Unavailable"
.If
data-available
is absent, add it with a value of"true"
and update the text content to"Available"
.
Display the Availability Status :
Check if the
data-available
attribute is present on the button;Display
"In Stock"
inavailability-status
ifdata-available
is present, or"Out of Stock"
if it's absent.
index.html
index.css
index.js
Use
textContent
to set the product name to"Smartphone"
;Use
value
to set the initial price to"499.99"
.Use
hasAttribute
to check if the<button>
has the attributedata-available
;If
data-available
is present, useremoveAttribute
to remove it and updatetextContent
to"Unavailable"
;If
data-available
is absent, usesetAttribute
to add it with a value of"true"
and updatetextContent
to"Available"
.Use
getAttribute
to check if thedata-available
attribute is present on the button.
index.html
index.css
index.js
Obrigado pelo seu feedback!