jQuery Form How to - Finds all inputs with an id attribute whose name attribute ends with m








Question

We would like to know how to finds all inputs with an id attribute whose name attribute ends with m.

Answer


<!--from  w w w. j  a va  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[id][name$='m']").val("asdf");
        });
    </script>
  </head>
  <body>
      <input id="a" name="m" />
  </body>
</html>

The code above is rendered as follows: