+ 1
Greetings, Coders please let me know that what the error here in JS
Greetings, I want to know the problem and solution of this code why I can't access the HTML elements with JS. I'm trying to do this but everytime I get null value. Thank you in advance. https://code.sololearn.com/W3CP5rKdqegz/?ref=app Thank you
9 ответов
+ 5
In sololearn, Put js code in
window.onload = () => {
// js code here...
}
+ 2
Use onload function
Try this:
onload = () => {
console.log(demo)
console.log(demo.innerHTML)
}
+ 1
onload = function() {
var demo = document.getElementById("demo").innerText;
let demo2 = document.querySelector("#demo").innerText;
console.log(demo2)
console.log(demo)
}
+ 1
Thank you everyone 🥺
+ 1
document.querySelector("#demo").style.color = "pink";
+ 1
Thank you but it's getting error please check
+ 1
Use this
document.querySelector("#demo").style.color = "pink";
+ 1
Thank you it worked 😋
0
Kindly let me know how can I add style in html via js code.