www.webdeveloper.com
Results 1 to 3 of 3

Thread: Single vs Double Quotes (Very Confusing!!)

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    81

    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.
    HTML Code:
    <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>


    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.

    HTML Code:
    <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>

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    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=\'gold\';" on ' ...

  3. #3
    Join Date
    Nov 2007
    Posts
    425
    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;;"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles