Reputation: 91
I have a table gathering data from mysql. I use jquery to highlight the negative data in red.
$(document).ready(function() {
$('td').each(function() {
var cellvalue = $(this).html();
if ( cellvalue.substring(0,1) == '-' ) {
$(this).wrapInner('<strong class="colorred"></strong>');
}
});
});
It works, but only in the last column, and i cant figure out why!!
any ideas?
here's the jsFiddle link http://jsfiddle.net/atseros/Af6Nz/17/
Upvotes: 0
Views: 3298
Reputation: 44740
Just use trim()
as you have unnecessary space in your td
-
var cellvalue = $.trim($(this).html());
Demo ---->
http://jsfiddle.net/Af6Nz/20/
Upvotes: 4
Reputation: 9646
Why don't you use if ( cellvalue < 0) {
$('td').each(function() {
var cellvalue = $(this).html();
if ( cellvalue < 0) {
$(this).wrapInner('<strong class="colorred"></strong>');
}
});
Upvotes: 2