jQuery attribute ends with selector

Description and Syntax

$('[foo$=bar]')

selects all elements that have the foo attribute with a value ending with bar.

Examples

SelectorSelects
$('[id$=yourValue]')all elements that have an ID ending with yourValue
$('input[name$=yourValue]')all <input> elements that have a name value ending with yourValue

The following code selects all inputs with an attribute name that ends with 'b'.


<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.  j ava2s  . co  m-->
            $("input[name$='b']").val("a");
        });
    </script>
  </head>
  <body>
    <body>
      <input name="ab" />
    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities