?
Solved

jQuery formatting strings

Posted on 2014-02-18
3
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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