/    Sign up×
Community /Pin to ProfileBookmark

Is this mouseover/out possible with css?

I want to use this on my page:

[CODE]<td onmouseover=”style.backgroundColor=#990000″ onmouseout=”style.backgroundColor=[COLOR=”DarkOrange”]#003366[/COLOR]”>[/CODE]

But I do not want to write the color of the onmouseout ([COLOR=”DarkOrange”]#003366[/COLOR]). I would like some script (or if possible css) to change the color back to the original color (#990000).

Is this possible?

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@rpgfan3233May 22.2008 — Not in Internet Explorer 6 or earlier, but IE7 and other browsers handle it just fine. As a result, a bit of JS still needs to be applied in IE6 and older (if you care about older versions than IE6). Here is my bit, though I can't really say whether it works in IE6 or not. I'm not very good with JS, but it should do what you need.
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;Blah&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

<i> </i>&lt;!-- the following block targets IE7 and newer as well as all non-IE browsers (excluding IE/mac) --&gt;
<i> </i>&lt;!--[if gte IE 7]&gt;&lt;!--&gt;
<i> </i>&lt;style type="text/css"&gt;
.example { background-color: #003366 }
.example:hover { background-color: #990000 }
&lt;/style&gt;
&lt;!--&lt;![endif]--&gt;

<i> </i>&lt;!-- target IE 6 and older --&gt;
<i> </i>&lt;!--[if lte IE 6]&gt;
<i> </i>&lt;script type="text/javascript"&gt;
<i> </i> function applyHover () {
<i> </i> var targetClassName = 'example';
<i> </i> var TDs = document.getElementsByTagName('td');
<i> </i> for (var i = 0; i &lt; TDs.length; i++)
<i> </i> {
<i> </i> if (TDs[i].className == targetClassName)
<i> </i> {
<i> </i> TDs[i].style.backgroundColor = '#003366';
<i> </i> TDs[i].onmouseover = function () { this.style.backgroundColor = '#990000'; };
<i> </i> TDs[i].onmouseout = function () { this.style.backgroundColor = '#003366'; };
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> window.onload = applyHover;
<i> </i>&lt;/script&gt;
<i> </i>&lt;![endif]--&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class="example"&gt;
Hello World!
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@marringiauthorMay 22.2008 — The thing is, that I have a template page that displays rows of data from a database. Every other row is white and every other row is gray. So I cannot set the color of which the onmouseout should be. I have to set the background color of the onmouseout in this script. Don't I?
Copy linkTweet thisAlerts:
@CentauriMay 22.2008 — You could set the background hover using the css :hover psuedo class on the <td>, and include the suckerfish javascript to apply the hover for IE6[CODE]#tableID td:hover, #tableID td.sfhover {
background-color: #990000;
}[/CODE]
×

Success!

Help @marringi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...