Solved

jQuery formatting strings

Posted on 2014-02-18
3
292 Views
Last Modified: 2014-02-18
Hi,

Hi All.
I have rows with positive and negative

<tr><td headers="MYCOL1">Sad Moving</td><td align="right" headers="MYCOL2"><a href="--mylink---">$33,131,131</a></td></tr>
<tr><td headers="MYCOL1">Air Flight</td><td align="right" headers="MYCOL2"><a href="--mylink---">-$22,121,121</a></td></tr>
<tr><td headers="MYCOL1">Glidding along</td><td align="right" headers="MYCOL2"><a href="--mylink---">$8,301,177</a></td></tr>
<tr><td headers="MYCOL1" style="background-color:blue"><b>Finished</b></td><td align="right" headers="MYCOL2" ><b>-$11,111,111</b></td></tr>

Open in new window


I would like to change the color of the negative numbers to red, remove the negative sign and put brackets around them

<$11,111,111>

thank you, Bill
0
Comment
Question by:bcarlis
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 300 total points
ID: 39868314
Something like this will get you going:

$('a').each(function() {
    value = $(this).text();
    if (value.indexOf("-") >= 0) {
        $(this).html("<" + value.slice(2) + ">").css('color', 'red');
    }
});

Open in new window

It will loop through all the A tags, and check if the text contains a minus sign. If it does, it trims off the first 2 characters (-$), wraps it in <> and sets the color to red
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39868501
yes, perfect!
0
 
LVL 2

Author Closing Comment

by:bcarlis
ID: 39868507
Chris, Thanks so much for your help!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now