Highlighting the cell on character (.) input only
I have this jquery code to highlight the table cell when a number is entered. I need highlighting only when a dot (.) is entered in the cell only. So when a dot (.) is entered in the cell, the highlight will take place, other times not. here is a fiddle example.
http://jsfiddle.net/k6p3ecL5/
thank you for your help.
html:
- <table>
- <tr>
- <td>
- <input type="text" class="number" />
- </td>
- <td>
- <input type="text" class="number" />
- </td>
- </tr>
- </table>
the jquery code is like this:
- $('.number').keyup(function() {
- var number = $(this).val();
- try {
- number = parseInt(number, 10);
- if (number > 0) {
- $(this).closest('td').addClass('highlight');
- } else {
- $(this).closest('td').removeClass('highlight');
- }
- } catch (e) {}
- });
css:
- td { border: 1px solid black; padding: 10px; }
- td.highlight { background-color: red; }