Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change HTML background with JavaScript Function?

How to change HTML background with JavaScript Function? I need some simple function to change background from one image to another?

like image 493
Rella Avatar asked Apr 11 '10 21:04

Rella


1 Answers

Try something like this:

function newBackGround (element,background) {
   element.style.backgroundImage = "url("+background+")";
}

newBackground (myElement,"newBackground.jpg");
like image 54
Jeff Fohl Avatar answered Oct 08 '22 23:10

Jeff Fohl