Solved

Changing table properties with JavaScript

Posted on 2001-09-07
10
561 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 200 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now