Changing background of a div

I want to change the background colour of a div.

does the this.style.background=‘’ accept hex colours…?

<div style="background-color:#D52638;" onmouseover="this.style.background='green';"  onmouseout="this.style.background='yellow';">
kuppiya.com
</div>


Yes, like this

onmouseover="this.style.backgroundColor='#84DFC1';"

Or whatever color :slight_smile:



<div style="background-color:#D52638;" onmouseover="this.style.background='#009ACF';"  onmouseout="this.style.background='#D526638';">
example 1
</div>

<div style="background-color:yellow" onmouseover="this.style.background='#009ACF';"  onmouseout="this.style.background='yellow';">
example 2
</div>



Example 1 doesn’t work

Example 2 works

Help

You have one too many characters here:


#D526638

You could do the first example in css only (apart from ie6 of course)

…Looks like I picked the wrong day to quit amphetamines.

tangledman, why use JS when CSS :hover does the same thing?

Because if he wanted to support IE6 then he could only do hover on anchors…though I do agree that the JS should only be used for IE6 and not generalized in the onmouseover obtrusive JS :slight_smile:

ah, i understand