jQuery attribute equals selector

Description and Syntax

$('[name=theValue]')

selects all elements that have the 'name' attribute with a value exactly equal to theValue.

Examples

SelectorSelects
$('[name=myname]')all elements that have a name value exactly equal to myname
$('a[rel=nofollow]')all <a> elements that have a rel value exactly equal to nofollow

The following code finds all inputs with name 'ab'.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from w w w  .  ja  va2  s  .  co  m-->
            $("input[name='ab']").val("ab");
        });
    </script>

  </head>
  <body>
    <body>
      <input name="ab" />
    </body>
</html>

Click to view the demo

Use two attribute selectors together

The following code does the matching with two attribute names.


<html>/*from w  w w  . ja v  a  2 s.  c  o  m*/
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("input[id][name='data']").val("data");
    });
    </script>
  </head>
  <body>
      <input id="end-data" name="data" />
  </body>
</html>




















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities