/    Sign up×
Community /Pin to ProfileBookmark

<tr> color swap onmouse over

Hey guys, i cannot figure out why this portion of my code is not doing as expected.

[CODE]var row = document.createElement(‘TR’);
row.setAttribute(‘onmouseover’,’this.style.color=”white”;this.style.backgroundColor=”#2172A1″; this.style.cursor=”default”;’);
row.setAttribute(‘onmouseout’,’this.style.backgroundColor=”white”;’);[/CODE]

The row changes color, but the text does not. It works fine if i do it for the cell itself.

Also, this code doesnot work at all in IE. I was told to use a different approach which would be:

[CODE]try{
var row = document.createElement(‘<tr style=”color=white;backgroundColor=#2172A1;”>’);
}catch(e){
var row = document.createElement(‘TR’);
row.setAttribute(‘onmouseover’,’this.style.color=”white”;this.style.backgroundColor=”#2172A1″; this.style.cursor=”default”;’);
row.setAttribute(‘onmouseout’,’this.style.backgroundColor=”white”;’)
}[/CODE]

I would just like to know as to what i am doing wrong here, i don’t want you guys to completly re-write the code, cause i would likt to try once i get an explanation as to what im doing incorrect.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FourCourtJesterOct 07.2008 — Well, if part of it fails in Firefox, and all of it fails in IE, it may be a javascript error. Have you tried running a debugger through your javascript?

also, try setting the text color to #FFFFFF (thats still white, just in hex)
Copy linkTweet thisAlerts:
@toicontienOct 07.2008 — This for JavaScript:
var row = document.createElement("tr");
row.onmouseover = function() {
this.className = "hover";
};
row.onmouseout = function() {
this.className = "";
};

And add this to your stylesheets:
.hover {
background-color: #2172A1;
color: #fff;
cursor: default;
}
Copy linkTweet thisAlerts:
@Declan1991Oct 07.2008 — Remember that onmouseover isn't an attribute, it's an inline event handler, that's why you should use either<i>
</i>row.onmouseover
or<i>
</i>row.addEventListener("mouseover",function(){},false); // W3C
row.attachEvent("onmouseover", function(){}); //IE
×

Success!

Help @keko2005 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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