/    Sign up×
Community /Pin to ProfileBookmark

CSS rollover on 1 table

Hello,

I have 2 tables on my page and want to add a rollover effect to the second one. See my html and css below. The problem is that at the moment the first table has a rollover effect, but I want it on the second. What did I wrong?

Thanks!

The html:

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “DTD/xhtml1-transitional.dtd”>
<html>
<head>
<link href=”style.css” rel=”stylesheet” type=”text/css” />
<script type=”text/javascript”>
<!–
var ss=0;
onload=function () {
var aTR=document.getElementsByTagName(‘tr’);

for (var i=0;i<aTR.length;i++) {
if (aTR[i].addEventListener) { // Mozilla
aTR[i].addEventListener(‘mouseover’, function() { highLight(this); }, false);
aTR[i].addEventListener(‘mouseout’, function() { highLight(this); }, false);
}
else {
aTR[i].onmouseover=function() {highLight(this);}
aTR[i].onmouseout=function() {highLight(this);}
}
}
}

function highLight(obj) {
if (obj.className != “hov”){
ss = obj.className;
obj.className = “hov”;
}
else{
obj.className=ss;
}
}
//–>
</script>
</head>
<body>
<div id =”filter”>
<table>
<tr><td>Test1</td><td><input type=”text” name=”t1″></td><td>sas</td><td>sas</td></tr>
<tr><td>Test1</td><td><input type=”text” name=”t1″></td><td>sas</td><td>sas</td></tr>
<tr><td>Test1</td><td><input type=”text” name=”t1″></td><td>sas</td><td>sas</td></tr>
</table>
</div>
<div id =”main”>
<table id=”sas”>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
<tr><td>Main</td><td>demo</td><td>sas</td><td>sas</td></tr>
</table>
</div>
</body>

</html>
[/code]

and my css is:

[code]
body {
margin:0px 0px 0px 0px;
padding:0px;
background:#ddd;
}

#filter {
width:350px;
background:#fff;
margin-left:auto;
margin-right:auto;
margin-top:50px;
}

#main {
width:550px;
background:#fff;
margin-left:auto;
margin-right:auto;
margin-top:10px;
}

table {
width:100%;
border:1px solid #aaa;
border-spacing: 0;
border-collapse: collapse;
}

td {
border:1px solid #aaa;
padding-left:2px;
}

table#sas td {
background:#DDF0BD;

}

.hov {
background:#DD10BD;
}

[/code]

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 15.2006 — var aTR=[COLOR=Green]document.getElementsByTagName('table')[1][/COLOR].document.getElementsByTagName('tr');
Copy linkTweet thisAlerts:
@elmuauthorMar 15.2006 — Thanks!

It is much better what I tought. Generaly my plan was to change the CSS definition somehow.

Anyhow is it possible to solve this with CSS? I know that technicaly this javascript version is better so it is only a theoretical question.
Copy linkTweet thisAlerts:
@KravvitzMar 15.2006 — Why is the JavaScript way better?

Use :hover.
#sas tr:hover {
background:#DD10BD;
}


IE(4 through 6)/Win only support :hover on <a> elements.

Three ways to simulate :hover in IE:

[url=http://dean.edwards.name/IE7/]Dean Edward's "IE7" patch for IE5-6[/url]

http://www.htmldog.com/articles/suckerfish/

[url=http://www.xs4all.nl/~peterned/csshover.html]whatever:hover[/url]
Copy linkTweet thisAlerts:
@bokehMar 15.2006 — Even though IE can take a bit of thought to overcome it is still possible to produce so very interesting [I]:hover[/I] effect that are purely CSS and that are fully functional in I.E. Have a look at these, not a boring tutorial: [URL=http://bokehman.com/rollover/]Singular CSS rollovers without Javascript[/URL].
Copy linkTweet thisAlerts:
@KravvitzMar 15.2006 — Yes, you can do that, but many elements are not allowed inside <a> elements. Anyway using an <a> element just because IE6 supports :hover on it natively is wrong.
×

Success!

Help @elmu 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...