javascript - Can't use this to point a selected element with jQuery -


why js not apply class element please ?

<input type="password" name="customer-new-password" class="form-control">  <script> if($("input[name='customer-new-password']").val()=='') {     $(this).addclass('required'); } else {     $(this).removeclass('required'); } </script> 

thanks.

why think $(this) point selected object?

try instead:

var $input = $("input[name='customer-new-password']"); if($input.val()=='') {     $input.addclass('required'); } else {     $input.removeclass('required'); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -