Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2004, 06:57 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get stylesheet's background color

I have a html page which include a stylesheet. I defined my stylesheet as below :

[code]

/* style.css */

tr.tblrow td {
   background-color: #def;
   color: #000;
   padding: 0px 5px;
}

[code]

And in my html page, I have a javascript function which will alert me about the background-color as well as font color.

Code:
<html>
<head>
<title>Bg Color</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script language="javascript" type="text/javascript">

function getColor(obj) {
   var el = event.srcElement;
   var txtColor = el.style.color;
   var bgColor = el.style.backgroundColor;

  alert("txtColor = " + txtColor);
  alert("bgColor = " + bgColor);
}

</script>
</head>

<form name="form">
<table>
   <tr class="tblrow" onClick="getColor(this); return false">
      <td>Student ID</td>
      <td>Student Name</td>
   </tr>
</table>
</form>
</html>
when I clicked on it, I get both color and background-color equal to blank. But, it suppose to be "txtColor = #000" and "bgColor = #def" .

Could anybody help to correct my mistake(s)? Thanks.

Reply With Quote
  #2 (permalink)  
Old October 31st, 2004, 07:57 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If in IE (don't know about others) then try currentStyle or runtimeStyle instead of style.

--

Joe
Reply With Quote
  #3 (permalink)  
Old October 31st, 2004, 08:03 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks joefawcett, it works.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change color of background meena88 C# 2005 3 December 1st, 2009 04:48 AM
Background Color matrix ArnieStewart BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 October 21st, 2008 01:12 AM
mdi-background color avats General .NET 1 February 28th, 2008 10:25 AM
background-color disappears harpua CSS Cascading Style Sheets 1 August 19th, 2005 04:53 PM
Status Bar Background Color kumar_garg78 Beginning VB 6 1 August 30th, 2004 11:46 PM



All times are GMT -4. The time now is 04:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.