JQuery Selector End With

From CoderLearner
Jump to: navigation, search

Description

Select the attribute with a value string ending exactly with a given string, and it is a case sensitive.

Syntax

$(Selector[name$="value"])

Example 1

Selected all class attributes that ended with a string pass.

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <style>
         .mark {
            background-color: red;
         }
      </style>
      <script>
         $().ready(function() {
            $('span[class$="pass"]').addClass("mark");
         });
      </script>
   </head>
   <body> 
      <span class="mark-3 gradepass">John</span>
      <span class="mark-4 grade-failed">Janny</span>
      <span class="mark-5 grade unknown">Paul</span>
      <span class="mark-5 gradepass">Christ</span>
   </body>
</html>

Try It

Example 2

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <style>
         .mark {
            background-color: red;
         }
      </style>
      <script>
         $().ready(function() {
            $('a[class$="class"]').addClass("mark");
         });
      </script>
   </head>
   <body> 
      <a href="#" class="sp_03 studentclass">John</a><br/>
      <a href="#" class="sp_31 studentteacher">Christ</a><br/>
      <a href="#" class="sp_34 classteacher">Bob</a><br/>
      <a href="#" class="sp_35 mathclass">Weeks</a><br/>
   </body>
</html>

Try It