简体   繁体   中英

How do I use javascript to change the font colour on my webpage?

I can't use JQuery sadly I need to use good old Javascript.

I have a forum and a black theme and when people use black text on it you can't see it. So I want to use javascript to change all the black text on the page to white when the page loads.

document.body.style.color = '#555555'

of course then you have to use the getElementById function instead of body if you want to select a specific element.

That's not really smart though. Go with CSS.

Other answerers have posted JavaScript solutions if you really want to use JS for this, so I won't add another. However, I just thought I'd offer two alternatives:

  • If you find that black is the default color for any posts, and you can modify your theme, don't use JavaScript for this — open your theme's CSS file, try to locate the style that makes post text black, and change it to white.

  • If black text is simply caused by people changing the color to be such in their own posts, I think a better idea would be to just tell your members not to use black text. I can also see legitimate uses of black text on black backgrounds, eg for a lack of spoiler tags in your forum software.

如果您是想动态更改主题/样式,则可以使用javascript通过通过document.getElementsByTagName(“ link”)选择链接标签来禁用和启用头部的CSS链接元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM