+ 2
How to use documemt.getElememtById function in JavaScript (sololearn).Because its not working.
7 odpowiedzi
+ 7
NISHA QURESHI: correct link is http://code.sololearn.com/WgU5IddVhcPC/
As guessed by Janning⭐ your JS code is executed before the page element you're trying to access is available (loaded), as the JS tab in code playground is linked to the Html tab/code in the <head> section: you need to wrap your code inside a function assigned to the window.onload event to defer its execution after the page load was completed (and element with id "di" was available)...
window.onload = function() {
var a=document.getElementById("di");
a.innerHTML="hello";
};
+ 9
You can see that, may be helpful.
all the best.
https://code.sololearn.com/WMuAJDhES1ca/?ref=app
+ 5
Hello, 😊
Please, if you want us to help you, then show us your attempt, what you don't understand exactly, where you are struggling, it will be much easier!👍😉
Use the search bar!
https://www.sololearn.com/post/10362/?ref=app
Please, read our guidelines:
https://www.sololearn.com/discuss/1316935/?ref=app
An useful code for any new user here!;)
https://code.sololearn.com/WvG0MJq2dQ6y/
+ 4
NISHA QURESHI
That is Not code!?
+ 2
Most likely you are running the script before loading the element you're trying to "get", so the function can't find the element. But really, you should be in the habit of linking the code so we can "look under the hood" per se, so that we're not leading you on a wild goose chase.
+ 1
http://www.sololearn.com/app/html/playground/WgU5IddVhcPC/
This code is not executing without error.