jQuery Selector How to - Select element that ends with a certain value








Question

We would like to know how to select element that ends with a certain value.

Answer


<!--from www  .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: