Solved

jQuery formatting strings

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
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 …

895 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