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
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 Display Modes
  #1 (permalink)  
Old April 11th, 2004, 07:15 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default 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>




Reply With Quote
  #2 (permalink)  
Old July 20th, 2004, 09:04 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use

tempCell.innerHTML = "" + response[i][j] + "";



Reply With Quote
  #3 (permalink)  
Old July 20th, 2004, 01:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

<><
Reply With Quote
  #4 (permalink)  
Old July 20th, 2004, 09:38 PM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Reply With Quote
  #5 (permalink)  
Old July 21st, 2004, 04:23 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

Reply With Quote
  #6 (permalink)  
Old July 22nd, 2004, 05:58 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Chris, it works.

Reply With Quote
  #7 (permalink)  
Old December 1st, 2009, 02:24 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default use jQuery - everything is possible and easy

Hello,
You can perform it using jQuery. Are you familiar with jQuery?
It is a javascript library that enables you to any visual tasks like dragging windows, made any picture rounded, etc.
for example notice following:
$("div > p").css("border","solid #0C0C0C 1px");
this means that change "border" propery of every "p" tag that is nested into a "div" tag, to "solid #0C0C0C 1px".

I put some files in my blog for you. by these you can learn to perform what you wanted and other things.

http://aspnet35.brinkster.net/beetle...i-20090115.chm

http://aspnet35.brinkster.net/beetle...ery-1.2-v1.chm

http://aspnet35.brinkster.net/beetle_jaipur/jquery.js

http://aspnet35.brinkster.net/beetle...uery.corner.js

jquery.js in main javascript library. you can even get a link from Google servers.
Reply With Quote
  #8 (permalink)  
Old December 1st, 2009, 04:49 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,038
Thanks: 80
Thanked 1,580 Times in 1,557 Posts
Default

This post is 5 years old!! What's the point of posting replies in old, dead threads?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old March 4th, 2010, 06:59 PM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by irProject View Post
Hello,
You can perform it using jQuery. Are you familiar with jQuery?
It is a javascript library that enables you to any visual tasks like dragging windows, made any picture rounded, etc.
for example notice following:
$("div > p").css("border","solid #0C0C0C 1px");
this means that change "border" propery of every "p" tag that is nested into a "div" tag, to "solid #0C0C0C 1px".

I put some files in my blog for you. by these you can learn to perform what you wanted and other things.

http://aspnet35.brinkster.net/beetle...i-20090115.chm

http://aspnet35.brinkster.net/beetle...ery-1.2-v1.chm

http://aspnet35.brinkster.net/beetle_jaipur/jquery.js

http://aspnet35.brinkster.net/beetle...uery.corner.js

jquery.js in main javascript library. you can even get a link from Google servers.
where can i find these files ?
___________________
indianapolis web design

Last edited by caligraphics; March 8th, 2010 at 03:21 PM.
Reply With Quote
  #10 (permalink)  
Old April 4th, 2010, 12:13 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

The right place to get jquery is http://jquery.com/. The current version of jquery is 1.4.2.

I do recommend jquery.
Reply With Quote
Reply


Thread Tools
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
change background color of inputbox vickriz Javascript How-To 3 December 1st, 2009 02:22 AM
change background color of toolbar control myth12345 VB How-To 1 January 6th, 2005 12:25 AM
Change the background color of a msgbox nobreferreira VB.NET 2002/2003 Basics 3 October 28th, 2004 10:37 AM
change background color of cell based on value vurtman ASP.NET 1.0 and 1.1 Basics 4 February 26th, 2004 03:52 PM



All times are GMT -4. The time now is 11:59 PM.


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