0
Javascript Doubt
I have doubt in js that is, how can I display an image in the website when a button is clicked ( that will not display automatically- I want it to display only when button is clicked) by accessing the id ? Everytime I try I do some mistakes. Please help me.
12 Respuestas
+ 1
Check this, I corrected it.
https://code.sololearn.com/W4kJ2U9mgbTG/?ref=app
+ 1
Use the onClick() function of javascript and the display property of css.
https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp
+ 1
Inside your function show(), write this:
let z = document.getElementById("yourimgid");
z.style.display="block";
0
Thanks Chetali Shah . But how can I add destination of the div to the button in js?
0
Gursimran Kaur You can fetch the ID of your div element inside your js script by using getElementById().
Look at the link that I shared earlier, it has an example which will give you clarity.
0
Chetali Shah okay, I got it. But I want that my button should display image not change color.
0
Then you fetch your img element by the getElementById() method.
0
You have to replace the "yourimgid" with the id of your image and the onclick event will go inside the button and not in your img tag.
0
The onclick() event will go inside your button tag and not in your img tag.
0
Thanks Chetali Shah, you helped me a lot!😊