jQuery Selector How to - Select attribute by value








Question

We would like to know how to select attribute by value.

Answer


<!--  w  ww  .jav a  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='me']").next().text(" changed");
    });
    </script>
  </head>
  <body>
      <div>
        <input type="radio" name="me" value="A" />
        <span>data</span>
      </div>
      <div>
        <input type="radio" name="me" value="B" />
          <span>data</span>
      </div>
      <div>
        <input type="radio" name="me" value="C" />
        <span>data</span>
      </div>
  </body>
</html>

The code above is rendered as follows: