Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Change Background Color

Reply
Thread Tools

Change Background Color

 
 
shapper
Guest
Posts: n/a
 
      10-19-2006
Hello,

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

Thank You,
Miguel

 
Reply With Quote
 
 
 
 
Benjamin
Guest
Posts: n/a
 
      10-19-2006
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


 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      10-19-2006
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>
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-19-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
rounded corners in which my border color is different than the background color laredotornado@zipmail.com Javascript 1 02-14-2007 07:37 AM
not able to click on background tab and backgrounds in properties to change the background. rex Computer Support 2 12-06-2006 02:26 AM
Problem with setting background color alternating item in datalist to a certain color fig000 ASP .Net Web Controls 0 09-06-2004 06:51 PM
How do i change background color to transparent Ather Ali Shaikh ASP .Net 1 12-04-2003 07:00 PM



Advertisments