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

14th Dec 2024, 9:18 AM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
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.
15th Dec 2024, 1:47 AM
Bob_Li
Bob_Li - avatar
+ 6
IFEANYICHUKWU HENRY OKWOR Yeah sometimes it is must but I use it in my every js project.
14th Dec 2024, 12:17 PM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 5
Wrap your js code inside window.onload function to make sure DOM content load completly before any script. window.onload = () => { //Your js code }
14th Dec 2024, 10:17 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 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
14th Dec 2024, 5:02 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Value is more for inputs (like text or number) or select (dropdowns)
15th Dec 2024, 5:50 AM
Zvi
Zvi - avatar
+ 1
Gulshan Mahawar thanks But why does the . value not work
14th Dec 2024, 10:56 AM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 1
And is it a must to use the onload when writing JavaScript
14th Dec 2024, 10:56 AM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 1
Thanks everyone who answered me Very grateful everyone
15th Dec 2024, 7:13 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
0
Also the . value does not work Please check ✅ it out of
14th Dec 2024, 9:26 AM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar