javascript - Adding Classes Based on Positive/Negative and Position -
i'm trying find way add class td based on whether it's positive or negative, not within first <tr>
, not within first <td>
of <tr>
.
i can't find on either issue through searching. know how this?
you mean if <td>
contains positive or negative number? if that's you're trying do, use this:
$(document).ready(function() { $("tr:not(:first)").find("td:not(:first)").each(function() { if ($(this).text() > 0) $(this).addclass("positive"); else if ($(this).text() < 0) $(this).addclass("negative"); }) });
i tested on following table , worked fine:
<table> <tr> <td>3</td> <td>9</td> <td>-3</td> </tr> <tr> <td>8</td> <td>-4</td> <td>9</td> </tr> <tr> <td>-7</td> <td>12</td> <td>144</td> </tr> </table>
Comments
Post a Comment