help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
2 Answers
+ 1
Your code is fine, the reason why its not working is because the javascript is loaded before the document itself. So the style you are trying to select, is not yet present in the DOM. To fix it, you can wrap your whole script in a function that executes when the window or document finished loading: window.onload = () => { var el=document.querySelector(".p1"); el.style.color="red"; }
4th Nov 2023, 12:03 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Thanks Tibor santa 🙏🙏
4th Nov 2023, 12:09 PM
Abdel Qb
Abdel Qb - avatar