Solved

jQuery formatting strings

Posted on 2014-02-18
3
295 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 43

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

810 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