innerHTML doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

innerHTML doesn't work

I tried to use the innerHTML on a paragraph and it didn' t work. please help me.

6th Feb 2021, 12:28 PM
Gabriele Giambrone
Gabriele Giambrone - avatar
14 Answers
+ 5
Nazeekk I managed to make it work, thanks for the help. idk why it didn't work.
7th Feb 2021, 11:26 AM
Gabriele Giambrone
Gabriele Giambrone - avatar
+ 9
Have a look at this example: https://code.sololearn.com/WXr5wf0KLFfe/?ref=app For using innerHTML and it works normally you have to use a script tag in html or onload the js in the js section (a window onload). Bcs if you don't use this method it comes error. It happened with me many times too, but I hope now you understand. For more add more details or the code. Happy coding :)
6th Feb 2021, 1:39 PM
Matthew
Matthew - avatar
+ 6
GabrieleYT9768 How did you try?
6th Feb 2021, 12:37 PM
A͢J
A͢J - avatar
+ 3
Tell more details🤔🤔
6th Feb 2021, 12:29 PM
Nazeekk
Nazeekk - avatar
+ 3
GabrieleYT9768 Smth like "document.getElementById("test").innerHTML = "text" ??
6th Feb 2021, 2:03 PM
Nazeekk
Nazeekk - avatar
+ 2
Nazeekk and I Am AJ ! I tryed with a function who had to change an empty paragraph but it didn't work
6th Feb 2021, 1:57 PM
Gabriele Giambrone
Gabriele Giambrone - avatar
+ 2
I think.. that's have to work🤔🤔
6th Feb 2021, 2:03 PM
Nazeekk
Nazeekk - avatar
+ 2
Nazeekk It's what i did and it didn' t work. i tried to use vars too, i tried to create one outside the function and inside but both didn't work. idk what to do, i need this function.
6th Feb 2021, 11:35 PM
Gabriele Giambrone
Gabriele Giambrone - avatar
+ 2
before you post the exact code we cqnt hwlp you
6th Feb 2021, 11:40 PM
John Doe
+ 2
I think.. maybe thats just because you use SoloLearn editor. Try to use "Brackets" or "VisualCode"
6th Feb 2021, 11:44 PM
Nazeekk
Nazeekk - avatar
+ 2
John Doe I'll make it
7th Feb 2021, 11:21 AM
Gabriele Giambrone
Gabriele Giambrone - avatar
+ 2
Nazeekk I did it, it's from a lot of time that it doesn't work
7th Feb 2021, 11:22 AM
Gabriele Giambrone
Gabriele Giambrone - avatar
0
Alyagout Babo What tf do you mean?
8th Feb 2021, 8:12 AM
Nazeekk
Nazeekk - avatar
- 1
<!DOCTYPE html> <html> <head> <title>Image selector viewer [demo for @Carl Moore]</title> </head> <body> <h1>Image selector viewer</h1> <h2>basic demo for @Carl Moore</h2> <p>Using &lt;iframe> for that purpose is too much heavy for nothing ^^ Just target an &lt;img> element instead, or even whatever element styled with a css background image...</p> <select onchange="setimg(this);"> <option></option> <option value="http://www.laboiteverte.fr/wp-content/uploads/2015/03/boucle-gif-geometrique-03.gif">image 1</option> <option value="http://www.laboiteverte.fr/wp-content/uploads/2015/03/boucle-gif-geometrique-02.gif">image 2</option> <option value="http://www.laboiteverte.fr/wp-content/uploads/2015/03/boucle-gif-geometrique-01.gif">image 3</option> </select> <img id="out"> </body> </html>
8th Feb 2021, 7:15 AM
Alyagout Babo
Alyagout Babo - avatar