Reputation:
i am new in JavaScript i want to set the background css through JavaScript how it possible can anyone help me.
element.style.backgroundColor = color;
Upvotes: 0
Views: 180
Reputation:
The background property sets or returns up to eight separate background properties, in a shorthand form.
With this property, you can set/return one or more of the following (in any order):
background-color
background-image
background-repeat
background-attachment
background-position
background-size
background-origin
background-clip
Example:
object.style.background="color image repeat attachment position size origin clip|initial|inherit"
Upvotes: 0
Reputation: 5356
document.bgColor for changing background color
function changeColor(){
color = document.getElementById("inpu").value;
document.bgColor=color;
}
<input type="text" value="red" id="inpu"><button onClick="changeColor()">Color</button>
Upvotes: 0
Reputation: 11
In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So background-color becomes backgroundColor.
function setColor(element, color){
element.style.backgroundColor = color;
}
Upvotes: 1
Reputation: 1917
document.body.style.background = "#f3f3f3 url('img_tree.png') no-repeat right top";
please check this link also Style background Property
Upvotes: 1