|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 11th, 2004, 07:15 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Change background color using CSS
The code I downloaded below was to change a 'td' field to right align if it was a currency. I tried to change the code so that it will display red when a negative number is displayed. It doesn't work. Do you know why?
<style type="text/css">
<!--
td.negative { background-color : red; }
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function PhoneHome() {
var shoePhone = document.getElementById('shoePhone');
shoePhone.src = "datafeed. js";
}
function ReceiveData(response) {
var table = document.getElementById('results');
var oldTbody = table.getElementsByTagName('tbody')[0];
var newTbody = document.createElement('tbody');
table.replaceChild(newTbody, oldTbody);
for (var i=0, istop=response.length; i<istop; i++) {
var tempRow = document.createElement('tr');
for (var j=0, jstop=response[i].length; j<jstop; j++) {
var tempCell = document.createElement('td');
var tempText = document.createTextNode(response[i][j]);
tempCell.appendChild(tempText);
tempRow.appendChild(tempCell);
if (tempText.nodeValue.indexOf('-') == 0) tempCell.setAttribute("class", "negative");
}
newTbody.appendChild(tempRow);
}
}
//-->
</script>
</head>
|

July 20th, 2004, 09:04 AM
|
|
Registered User
|
|
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I use
tempCell.innerHTML = "" + response[i][j] + "";
|

July 20th, 2004, 01:08 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Since this topic has come up....
innerHTML is IE only, and the attribute is depreciated.
Personally, I don't care for the fancy setAttribute() and createElement() functions, why not just print it out directly? Aren't those IE only, anyway? Not sure.... :-)
HTH,
Snib
<><
|

July 20th, 2004, 09:38 PM
|
|
Registered User
|
|
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Snib, it is for Flickering.
I encountered this problem same as "pigtail". I don't have time to find better way to solve it. That is why I cut it short. Any better suggestion?
Simon
|

July 21st, 2004, 04:23 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 685
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Simon,
The original code
Code:
tempCell.setAttribute("class", "negative");
works in Mozilla / NS6+ etc, but fails in IE. You can get around it by using:
Code:
tempCell.className = "negative";
HTH,
Chris
|

July 22nd, 2004, 05:58 AM
|
|
Registered User
|
|
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Chris, it works.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |