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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World