Gistlib Logo

gistlib

change the background to red in javascript

To change the background color of a webpage to red using Javascript, you can use the following code:

index.tsx
document.body.style.backgroundColor = "red";
45 chars
2 lines

This code selects the body element of the webpage and sets its background color to red using the style property. You can replace "red" with any valid CSS color value to change the background color to something else.

similar javascript code snippets

center a div in javascript
create a carousel in html in javascript
create a div that scrolls horizontally and adjust its height to always be 80% of the screen height in javascript
scroll snap in javascript
how to toggle a class on an element in javascript
blue coloured cta in javascript
create a div of images that is always no bigger than 80% of the display height and the images scale accordingly. when you hover over an image it zooms slighly and the other images gray out in javascript
create a div that scrolls horizontally and adjust the height of its content to always be 80% of the screen height in javascript
how to remove a class from an element in javascript
how to change the border of an element in javascript

related categories

javascript
web development
front-end development
css
dom manipulation

gistlibby LogSnag