One thing to remember is that selectors are applied in order.
$('td:nth(3):positive') gives you the positive numbers that are in the
fourth cell,
$('td:positive:nth(3)') gives you the fourth positive cell, probably not
what you want

Danny Wachsstock wrote:
> 
> To select specific elements, the cool kids all use custom selectors (not
> very well documented, but see
> http://docs.jquery.com/Plugins/Authoring#Using_jQuery.extend_to_extend_jQuery_itself
> and
> http://www.softwareunity.com/sandbox/JQueryMoreSelectors/ )
> 
> Basically, extend jQuery.expr[':'] with a string that will be evaluated to
> true if you want that item selected.
> You can use the variables 'a' for the element being considered, 'm[3]' for
> whatever was in parentheses in the selector (as in the '2' in 'nth(2)' ),
> 'i' for the index of the element being considered, and 'r' for the whole
> array of elements.
> 
> In short:
>   jQuery.extend(jQuery.expr[":"], {
>     positive : "parseFloat($(a).text()) > 0",
>     negative : "parseFloat($(a).text()) < 0",
>   });
> does what you want.
> 
> Use it like:
> 
> $('td:negative').css('color', 'red');
> $('td:positive').css('color', 'green');
> 
> Danny
> 
> 
> rolfsf wrote:
>> 
>> Is there a clever way in jQuery to find non-zero data in specific columns
>> of a table, and assign them a class based on whether they are positive or
>> negative? In plain English, I want to make positive numbers green (or the
>> cell bg) and the negative numbers red, but only in certain columns.
>> Ideally, I would want to fine tune the range - say, > 1.5 is green and <
>> -1.5 is red. I suspect that COL and COLGROUP are not very useful as
>> selectors.
>> 
>> Thanks!
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/adding-a-class-to-positive-and-negative-data-cells-in-a-table-column-tf3240521.html#a9026794
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to