开发者

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

开发者 https://www.devze.com 2023-01-15 13:29 出处:网络
I can\'t use JQuery sadly I need to use good old Javascript. I have a forum and a black theme and when peopl开发者_JAVA技巧e use black text on it you can\'t see it. So I want to use javascript to cha

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

I have a forum and a black theme and when peopl开发者_JAVA技巧e 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 getElementByIdfunction 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, e.g. for a lack of spoiler tags in your forum software.


If you mean you want to dynamically change your theme/styles you can use javascript to disable and enable css link element in the head by selecting link tags via document.getElementsByTagName("link")

0

精彩评论

暂无评论...
验证码 换一张
取 消