jQuery Selector How to - Select attribute and it ends with a certain value








Question

We would like to know how to select attribute and it ends with a certain value.

Answer


<!--from  w w w . ja  va  2 s  .co 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$='Abc']").val("data");
    });
    </script>
  </head>
  <body>
      <input name="Abc" />
      <input name="Bcd" />
      <input name="Cde" />
  </body>
</html>

The code above is rendered as follows: