javascript - jQuery with Input Type = "Number" -
simple question, looking right way handle this.
i've broken down simplistic example still shows problem.
let's have basic html table:
<table id="customertable"> <caption class="bg-primary h4">customer overview</caption> <thead> <tr> <th>customer id</th> <th>customer name</th> <th># projects</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>enterprise management</td> <td>14</td> </tr> <tr> etc ... </tr> </tbody> </table>
then have input type:
<input id="colorcolumnred" type="number" />
the jquery follows, redtext
being basic css change color red. i'm handling both change
, keyup
events try capture 2 situations.
$(function () { $('#colorcolumnred').bind('change keyup', function () { var colid = $('#colorcolumnred').val(); $('#customertable td:nth-child(' + colid + ')').toggleclass('redtext'); }); });
the problem is, when user types number numeric field works expected. however, if change focus input, css reverts.
if use numeric up/down selector instead, change persists after control loses focus.
what missing jquery selector stop reverting when manually entered on losing focus? i've tried various focus
events, blur
, etc , can't find 1 changes behavior.
@rayon dabre quick answer easy, quick fix.
$('#colorcolumnred').bind('input')
Comments
Post a Comment