473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Change Background Color

Hello,

How can I change the background color of a DIV when the mouse is over
it?

Thank You,
Miguel

Oct 19 '06 #1
3 2007
here's the script:
<script type="text/javascript">
function changeTo(div) {
div.style.backgroundColor = "red";
}
function changeFrom(div) {
div.style.backgroundColor = "white";
}
</script>

Your div should like somthing like this:
<div onmouseover="changeTo(this)" onmouseout="changeFrom(this)">Some
stuff</div>

shapper wrote:
Hello,

How can I change the background color of a DIV when the mouse is over
it?

Thank You,
Miguel
Oct 19 '06 #2
ASM
Benjamin a écrit :
here's the script:
and here's another one :

css :
=====
..onRed { background: lightyellow; }
..onRed:hover { background: yellow; }

javascript :
============
var IE = false; /*@cc_on IE=true; @*/

function roll(what) {
if(IE) {
what = what.style;
what.backgroundColor = what.backgroundColor==''? 'yellow' : '';
}
}

html :
======
<div class="onRed"
onmouseover="roll(this);"
onmouseout="roll(this);">
bla bla blabla
</div>
Oct 19 '06 #3
ASM wrote:
[...]
css :
=====
.onRed { background: lightyellow; }
.onRed:hover { background: yellow; }

javascript :
============
var IE = false; /*@cc_on IE=true; @*/
IE 7 is supposed to support hover on elements other than A, so you
might want to reconsider using browser sniffing with script and switch
to pure CSS.
--
Rob

Oct 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: carramba | last post by:
Hi! is it possible to change "selector" color in drop-down list? <select name="select" style="background-color: #ff0000"> <option style="background-color: #ff0000" value="1">Cony</option>...
4
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent...
5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
3
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make...
2
by: Sean | last post by:
Hi all, I have a treeview and because I subclass the treeview and allow multiple selection to be done on the treeview, I have a problem changing the background color of the treeview. The...
2
by: chris_culley | last post by:
Hi there, I've got a gif with (highly) irregular shapes (lots of jigsaw pieces) that I want to map so that each piece is a link... The pieces are currently just a frame drawing, but as they...
1
by: roN | last post by:
Hi, I have a table in which I would like to change the background image onMouseOver. I implemented it with CSS but IE doesn't support hovers on tables, so I'd need to go via JS for IE. Can...
4
by: martin1 | last post by:
Hi, want to loop DataSet to change row background color based on data retrieved from sql db, the color can be blue, yellow, red or purple. Therefore, Is there any way (vb.net) to change dataset...
4
by: html | last post by:
Hello all, I need to change the colour of my text. For the paragraph I do document.fgColor ="blue" ; but how do I do this for the select tags? ....and I prefer it to apply to all select tags...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.