+ 2

How to use documemt.getElememtById function in JavaScript (sololearn).Because its not working.

9th Dec 2018, 11:20 AM
NISHA QURESHI
NISHA QURESHI - avatar
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"; };
9th Dec 2018, 12:15 PM
visph
visph - avatar
+ 9
You can see that, may be helpful. all the best. https://code.sololearn.com/WMuAJDhES1ca/?ref=app
30th Dec 2018, 6:45 AM
Moree
Moree - avatar
+ 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/
9th Dec 2018, 11:31 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
NISHA QURESHI That is Not code!?
9th Dec 2018, 12:03 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
9th Dec 2018, 11:39 AM
Janning⭐
Janning⭐ - avatar
+ 1
http://www.sololearn.com/app/html/playground/WgU5IddVhcPC/ This code is not executing without error.
9th Dec 2018, 11:52 AM
NISHA QURESHI
NISHA QURESHI - avatar