Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing table properties with JavaScript

Posted on 2001-09-07
10
Medium Priority
?
582 Views
Last Modified: 2013-11-19
I've made a small table in a html page:

<html><head>
<title>Test</title>
<style type="text/css">
<!--
.tableLayout { background-color: #f1f1f1; border: 1px #999999 solid }
td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000 }
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table cellSpacing=0 cellPadding=2 width=180 border=0 class="tableLayout">
  <tr><td>Menu 1</td></tr>
  <tr><td>Menu 2</td></tr>
  <tr><td>Menu 3</td></tr>
</table>
</body></html>

The table has a backgroundcolor and a small solid border.
Now I would like to create the following effect. When I move the mouse over a cell, the backgroundcolor and bordercolor of that cell has to change. I know how to do it with CSS, but it has to be done width JavaScipt.

I think it should look something like this:
<td onMouseOver="changeLayout();" ...>

Can somebody help how to change html and css elements using JavaScript?

The ideal result I hope to get is something like the left menu on the Microsoft website (http://www.microsoft.com)
0
Comment
Question by:StievieD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
10 Comments
 
LVL 8

Expert Comment

by:edemcs
ID: 6463995
I'm not sure how to do it with Javascript, and I know you said you know how to do it using css, but if you haven't thought of this method before, here it is.  Good luck


function changerow(objRow,color)
     {
     objRow.style.backgroundColor=color;
     }


<TR BGColor="FFFFFF" OnMouseOver="changerow(this,'eeea88');" OnMouseOut="changerow(this,'FFFFFF');">
0
 
LVL 8

Expert Comment

by:edemcs
ID: 6464003
I'm not sure how to do it with Javascript, and I know you said you know how to do it using css, but if you haven't thought of this method before, here it is.  Good luck


function changerow(objRow,color)
     {
     objRow.style.backgroundColor=color;
     }


<TR BGColor="FFFFFF" OnMouseOver="changerow(this,'eeea88');" OnMouseOut="changerow(this,'FFFFFF');">
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6464008
<!-- These are IE only functions!!  It may be possible to get it to work in
     Netscape 6 if it knows what className is
-->

<html>
<head>
<title> cell changer </title>
<style>
<!--
   .green {background-color:green;color:yellow;border:2px solid navy;
        font-family:arial;cursor:hand}
   .white {background-color:white;color:teal;border:2px solid gray}
   body {background-color:lime}
-->
</style>
<script language="JavaScript">
<!--
   function chgcell(EL,color)
   {
      var lastcell=EL;
      lastcell.className=color;
   }
//-->
</script>
</head>
<body>
<table border=5>
<tr>
<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the first cell
</td>

<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the second cell
</td>
<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the third cell
</td>

<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the fourth cell
</td>
</tr>
<tr>
<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the fifth cell
</td>

<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the sixth cell
    <br>
    <a href="blah.gif" class="specialA"> this is a link </a>
</td>
<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the seventh cell
</td>

<td width=150 height=60 align="center" valign="middle"
    class="white"
    onMouseover="chgcell(this,'green')"
    onMouseout="chgcell(this,'white')">
    this is the eighth cell
</td>
</tr>
<tr>
</table>
</body>
</html>

<!-- using this type of format, we can make any cell
modify itself or any other cell on any supported
event

The current format passes this to the function, but
the function can be easily modified to accept the
id of another cell for modification.

If these are the fucntions you're looking for, we can do what
we have to make them work in your environment. But IE only!
Netscape does not support the className attribute of the DOM

Cd&
-->
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:edemcs
ID: 6464013
I'm not sure how to do it with Javascript, and I know you said you know how to do it using css, but if you haven't thought of this method before, here it is.  Good luck


function changerow(objRow,color)
     {
     objRow.style.backgroundColor=color;
     }


<TR BGColor="FFFFFF" OnMouseOver="changerow(this,'eeea88');" OnMouseOut="changerow(this,'FFFFFF');">
0
 
LVL 8

Expert Comment

by:edemcs
ID: 6464052
I'm not sure how to do it with Javascript, and I know you said you know how to do it using css, but if you haven't thought of this method before, here it is.  Good luck


function changerow(objRow,color)
     {
     objRow.style.backgroundColor=color;
     }


<TR BGColor="FFFFFF" OnMouseOver="changerow(this,'eeea88');" OnMouseOut="changerow(this,'FFFFFF');">
0
 
LVL 8

Expert Comment

by:edemcs
ID: 6464067
first of all, sorry about all of the posts, I must have refreshed the screen to many times.  My method does work on Netscape 6 and IE.
0
 

Author Comment

by:StievieD
ID: 6464102
edemcs Your solution works really great. I still have a single question.

In your solution you use 'objRow.style.backgroundColor' Which other options can I use behind 'style.' What can use for example to change the border size and color also?

I ask this because the words used in JavaScript and CSS are not the same. Example: CSS=background-color <=> JavaScript=backgroundColor.

Have you got a list or something of the thing I can change with 'style.'?
0
 
LVL 8

Accepted Solution

by:
edemcs earned 600 total points
ID: 6464193
0
 
LVL 8

Expert Comment

by:edemcs
ID: 6464239
StevieD, no A??!!! :) Thanks.
0
 
LVL 8

Expert Comment

by:edemcs
ID: 6464243
StevieD, no A??!!! :) Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question