I’m an absolute begginer in html, css and js. And I want a video to pop up when I click a button and disappear when I click the button again. I’ve tried to found a video in korean but there aren’t any videos about it. How can I make this?
I’m an absolute begginer in html, css and js. And I want a video to pop up when I click a button and disappear when I click the button again. I’ve tried to found a video in korean but there aren’t any videos about it. How can I make this?
2
Answers
It’s possible with Bootstrap 5:
If you want to learn more about modals and their customization, check this out.
Hope this helps!
First, add class
.hide
in css and setvisibility: hidden;
this will hide anything that you assign class "hide" to.
Now we grab the button element with query selector and add eventListener to it. If you dont know what those are,
document.querySelector('')
grabs the first element in html with the name'elementname'
for element,'.classname'
for class and'#idname'
for id. More about that here.Lets say our button has
id="removeVid"
As you can see I also added
addEventListener()
, which you can check out here.I’ll now declare a variable
videoHidden = false
, that we will change when we show/hide it.After that, I’ll make an if else statement that will give class
hide
to video if its not hidden yet, and remove classhide
if it is hidden.Hope this helped and feel free to ask questions if anything is unclear.
EDIT: If you want it to be hidden at first, add class
.hide
to the video in html :).