/    Sign up×
Community /Pin to ProfileBookmark

Single vs Double Quotes (Very Confusing!!)

The row in the table would highlight whenever I mouse over it.

This works perfectly in HTML but I would like to convert from HTML code to Javascritp code to make it more dynamic.

[code=html]<html>
<body>

<TABLE border=1>
<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>
<TD>Mauritania</td><TD>21N</TD><TD>24N</TD><TD>&nbsp;</TD><TD>&nbsp;</TD>
</TR>
<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>
<TD>Myanmar</td><TD>&nbsp;</TD><TD>M TBA</TD><TD>M TBA</TD><TD>&nbsp;</TD>
</TR>
<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>
<TD>Nepal</td><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>M TBA</TD>
</TR>
</TABLE>

</body>
</html>[/code]

I tried to convert it to Javascript but it only gives me a blank screen.
This is very frustrating because I don’t know where I’m going wrong.
Any comments of suggestions would be greatly appreciated.

[code=html]<html>
<head>
<script type=”text/javascript”>

function init(){
document.writeln(‘<TABLE border=1>’);

document.writeln(‘<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>’);
document.writeln(‘<TD>Mauritania</td><TD>21N</TD><TD>24N</TD><TD>&nbsp;</TD><TD>&nbsp;</TD> </TR>’);

document.writeln(‘<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>’);
document.writeln(‘<TD>Myanmar</td><TD>&nbsp;</TD><TD>M TBA</TD><TD>M TBA</TD><TD>&nbsp;</TD></TR>’);

document.writeln(‘<TR bgcolor=”#FFFFFF” onMouseOver=”this.bgColor=’gold’;” onMouseOut=”this.bgColor=’#FFFFFF’;”>’);
document.writeln(‘<TD>Nepal</td><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>M TBA</TD></TR></TABLE>’)’;
}
</script>
</head>

<body onload=”init()”>
</body>
</html>[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rnd_meJun 07.2012 — just use css with td:hover; why make it more complex than needed?

if you must, escape the nested single quotes :

[CODE]'<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor=[COLOR="Red"][/COLOR]'gold[COLOR="Red"][/COLOR]';" on ' ...[/CODE]
Copy linkTweet thisAlerts:
@nap0leonJun 07.2012 — Hover is nice if you are able to.

FYI in case you you don't like doing ', like this:

onMouseOver="this.bgColor='gold'" onMouseOut="this.bgColor='#FFFFFF';"

you can use &quot for your quotes, like this:

onMouseOver="this.bgColor=&quot;gold&quot;" onMouseOut="this.bgColor=&quot;#FFFFFF&quot;;"
×

Success!

Help @locbtran 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.18,
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,
)...