jQuery Form How to - Select all inputs with a name attribute that contains 'a'








Question

We would like to know how to select all inputs with a name attribute that contains 'a'.

Answer


<!--from w  ww .  j a  v  a2 s. c  om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name*='a']").val("a");
        });
    </script>
  </head>
  <body>
      <input name="a" />
  </body>
</html>

The code above is rendered as follows: