?
Solved

Changing table properties with JavaScript

Posted on 2001-09-07
10
Medium Priority
?
576 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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 article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…
Suggested Courses

770 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