I want to get all the paragraph tags on a page to be white by putting something into the console. I tried something like this:
document.p.style.color = 'white';
but that did not work. I know changing the body tag works in the console tho
document.body.style.background = 'black';
CodePudding user response:
Here is an example code for your answer:
HTML:
<p id="ANYTHING_YOU_WANT">ANYTHING_YOU_WANT</p>
JS:
const VARIABLE_NAME = document.getElementById("ANYTHING_YOU_WANT");
VARIABLE_NAME.style.color = "aqua";
Give your class and text instead of ANYTHING_YOU_WANT and your variable name instead of VARIABLE_NAME...
CodePudding user response:
You would need to select paragraph individually or select them in bulk to change their properties.
Since there is only 1 body
document.body
worksBut there can be multiple paragraphs so
You either need to select them by thier id `**
document.getElementById("Id")
**` or you could do **
document.querySelectorAll('p').forEach(p => p.style.color = 'white');
**