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";
}
+ 1
Thanks Tibor santa đđ