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

x
?
Solved

onmouseover event to change text color in a JS created table

Posted on 2007-04-03
3
Medium Priority
?
1,190 Views
Last Modified: 2012-06-21
I have a HTML table with many rows! When I mouseover "td", I want to change the text color inside the "td".

Problem is that the HTML table is designed in Javascript using:

a = document.createElement("table")
a.id = "my_tbl";

How is it possible to add onmouseover event for "td" of this table "my_tbl" that changes the "td's" text color ?!

Quite urgent.. Thanks :)
0
Comment
Question by:ldbkutty
[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
  • 2
3 Comments
 
LVL 30

Assisted Solution

by:VirusMinus
VirusMinus earned 800 total points
ID: 18843367
hmm.. easiest way i can think of is to download this file which allows CSS behavior of :hover to extend to other elements for IE 6.

http://www.xs4all.nl/~peterned/htc/csshover2.htc

put the file in the root folder of your site.

and then in your CSS add:

body{BEHAVIOR: url(csshover.htc)}
#my_tbl td:hover{background:red;}

ref: explanation about csshover.htc here: http://www.xs4all.nl/~peterned/csshover.html
0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 18843376
then again, it may not work for javascript created elements.

where are you adding the cells? in that code you can use onMouseOver for the cells
0
 
LVL 28

Accepted Solution

by:
TName earned 1200 total points
ID: 18843762
As VirusMinus said, or have a look at this and see if it is what you are looking for:


<html>
<head>
<script>

function detour(thing){
   var temp = thing;
   return function(){
    mouseOverCell(temp)
   }
}

function mouseOverCell(obj)
{
  obj.style.color='#f00';
}

function makeTable() {  

  var tbl=document.createElement("TABLE");
  tbl.border=1;
  tbl.cellSpacing=1;
  tbl.id = "my_tbl";
  var r=document.createElement("TR");
  var cell1=document.createElement("TD");
  cell1.innerHTML="Test 1";
  cell1.onmouseover=detour(cell1);
  var cell2=document.createElement("TD");
  cell2.innerHTML="Test 2";
  cell2.onmouseover=detour(cell2);
  r.appendChild(cell1);
  r.appendChild(cell2);
  var tbd=document.createElement("TBODY");
  tbd.appendChild(r);
  tbl.appendChild(tbd);
  document.body.appendChild(tbl);
}

</script>
</head>
<body>
<input type="button" onClick="makeTable()">
<br>
<br>
</body>
</html>

See explanation here:
http://ncyoung.com/archive.php?startDate=2005-7-1&endDate=2005-8-1  ("closures for event handlers with parameters")

0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

610 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