简体   繁体   中英

Javascript affect a div on hover

Hello guys i have just written this code.All I want is simply hover the cursor over this buttons and affect the div that's on their right side. The problem i have now is that i can't link any image.Only colors.But i don't want colors. I know that's is simple but is slipping my mind right now.

<script> function chbg(color){document.getElementById('container2').style.backgroundColor=color;} </script>

<button id="button1" onmouseover="chbg('red')" onmouseout="chbg('whitesmoke')"></button>
<script>
function chimage(url) {
    document.getElementById('container2').style.backgroundImage = 'url('+url+')';
}
</script>

<button id="button1" onmouseover="chimage('/path/to/hoverimage.jpg')" onmouseout="chimage('/path/to/plainimage.jpg');"></button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM