0
Javascript
I tried writing this external Dom in js and it did not work . I now wrote another one in internal and it worked Any problem why it didn't work https://sololearn.com/compiler-playground/Ww6wlpHOVz8X/?ref=app
9 ответов
+ 3
b is a div.
divs don't have value. that's why the console.log is giving 'undefined'.
use
let b= document.getElementById("ge").textContent;
instead.
also, write all your script tag inside the <body></body> tags, or put them all in the js tab inside onload=()=>{}, avoid using both at the same time.
+ 6
IFEANYICHUKWU HENRY OKWOR
Yeah sometimes it is must but I use it in my every js project.
+ 5
Wrap your js code inside window.onload function to make sure DOM content load completly before any script.
window.onload = () => {
//Your js code
}
+ 3
It's because the Sololearn compiler runs JavaScript before html... or something along those lines. Your js can't find any references to the unloaded html file, so tell js to wait with the onload and it should work fine.
Thanks Gulshan Mahawar
+ 3
Value is more for inputs (like text or number) or select (dropdowns)
+ 1
Gulshan Mahawar thanks
But why does the . value not work
+ 1
And is it a must to use the onload when writing JavaScript
+ 1
Thanks everyone who answered me
Very grateful everyone
0
Also the . value does not work
Please check ✅ it out of