Solved

jQuery formatting strings

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

840 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