innerHTML doesn't work | Sololearn: Learn to code for FREE!


innerHTML doesn't work

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

2/6/2021 12:28:47 PM

Gabriele Giambrone

15 Answers

New Answer


Nazeekk I managed to make it work, thanks for the help. idk why it didn't work.


Have a look at this example: 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 :)


GabrieleYT9768 How did you try?


Tell more details🤔🤔


GabrieleYT9768 Smth like "document.getElementById("test").innerHTML = "text" ??


Nazeekk and I Am AJ ! I tryed with a function who had to change an empty paragraph but it didn't work


I think.. that's have to work🤔🤔


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.


before you post the exact code we cqnt hwlp you


I think.. maybe thats just because you use SoloLearn editor. Try to use "Brackets" or "VisualCode"


John Doe I'll make it


Nazeekk I did it, it's from a lot of time that it doesn't work


Alyagout Babo What tf do you mean?


<!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="">image 1</option> <option value="">image 2</option> <option value="">image 3</option> </select> <img id="out"> </body> </html>