javascript - How to add or remove class to each if element changed -


i have form jquery-validate , jquery-steps. need check, if 1 of fields not empty, other in same row must filled. know elements class "required" must filled. leave every element without class required. before going next step, must check if there not empty element. if there @ least one, must add class "required" inputs in same row. example if input "name" filled, input "surname" , input "email" must filled too.

<table bolder=1"> <thead> <tr> <th>name</th> <th>surname</th> <th>email</th> </tr> </thead> </table> <tbody> <tr> <td> <input class="documentcheck" type="text"> </td> <td> <input type="text"> </td> <td> <input type="text"> </td> </tr> <tr> <td> <input class="documentcheck" type="text"> </td> <td> <input type="text"> </td> <td> <input type="text"> </td> </tr> <tr> <td> <input class="documentcheck" type="text"> </td> <td> <input type="text"> </td> <td> <input type="text"> </td> </tr> </tbody></table> 

here have done before understand im dummy: fiddle

 $(function () {      $(".documentcheck").change(function () {          name = $(".documentcheck").val();          if (name.length > 0) {              $("td").find('.req').first().addclass("required");          }      });  }); 

thanks in advance

do this:

     $(document).ready(function(){         $(".documentcheck").on('change',"td > input",function() {              $(this).parent().siblings().children('input').addclass('required');          });      }); 

fiddle

updated fiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -