Posts tagged ‘html’

May 19th, 2010

Change the background of many div on a rollover

First you need a method to change the background of a div :


function changeDivBkg(divId, imgSrc) {
document.getElementById(divId).style.backgroundImage = 'url(' + imgSrc + ')';
}

After that change the onMouseOver content of a div like that :


<div onMouseOver="changeManyDivBkg()">

Now the easy part, you can add so many lines as needed :


function changeManyDivBkg() {
changeDivBkg('divId1', 'image1.jpg');
changeDivBkg('divId2', 'image1.jpg');
}