通过控制台更改段落标签颜色

发布于 2025-02-12 13:39:16 字数 207 浏览 2 评论 0原文

我想通过将某些内容放入控制台上,将所有段落标签放在页面上是白色的。我尝试了这样的事情:

document.p.style.color = 'white';

但是那无效。我知道更改身体标签在控制台中起作用

document.body.style.background = 'black';

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';

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大姐,你呐 2025-02-19 13:39:16

这是您答案的示例代码:

html:

<p id="ANYTHING_YOU_WANT">ANYTHING_YOU_WANT</p>

js:

const VARIABLE_NAME = document.getElementById("ANYTHING_YOU_WANT");

VARIABLE_NAME.style.color = "aqua";

给您的课程和文本,而不是 nothing_you_want 和您的变量名称,而不是 variable_name...

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...

℡Ms空城旧梦 2025-02-19 13:39:16

您需要单独选择段落或批量选择它们以更改其属性。

因为只有1个正文document.body works

但是可以有多个段落,所以

您要么需要通过其ID选择它们

document.getElementById(“ id”);

,也可以做:

document.queryselectorall('p')。foreach(p =&gt; p.style。 color ='White');

You would need to select paragraphs individually or select them in bulk to change their properties.

Since there is only 1 body document.body works

But there can be multiple paragraphs so

You either need to select them by their id

document.getElementById("Id");

or you could do:

document.querySelectorAll('p').forEach(p => p.style.color = 'white');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文