jQuery Form How to - Select all inputs with an attribute name that ends with 'b'








Question

We would like to know how to select all inputs with an attribute name that ends with 'b'.

Answer


<!--from ww  w  .  j  a  v a 2 s .  c o m-->
<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$='b']").val("a");
        });
    </script>
  </head>
  <body>
      <input name="ab" />
  </body>
</html>

The code above is rendered as follows: